File Exchange

image thumbnail

Find unused plot color

version 1.1 (1.67 KB) by

Find the first unused default color in a plot or generate a random one.



View License

Whenever plots are generated inside a loop with the figure put on hold, the normal plot command plots everything in the same color. When a different color is wanted, normally a color-vector needs to be generated.
With this function it is possible to call the color inside the plot command, using
plot(x,y,'color', which_color(gca))

It first uses all the specified colors in the ColorOrder. If all of them are used it generates a random color.

Comments and Ratings (3)

Jan Simon

Jan Simon (view profile)

Works as explained in the help text, has a H1-line to support LOOKFOR, date, author, version history, comments in the code, efficient, useful and usable.


Thanks again Jan for your suggestions to improve the code quality, I'll soon upload an updated version!

Jan Simon

Jan Simon (view profile)

The function fails, if a line was drawn using a CHAR color specifier as 'r', 'g', 'b' etc.
The first line of the help text should be "not present in the axes", not " the figure".
"NaN(length(h_lines), 3)" is faster than "ones()*NaN". But ZEROS() would do it also, because all values are overwritten soon.
The search for the color can be simplified:
found = any(default_color(k,1)==curr_color(:,1) & default_color(k,2)==curr_color(:,2) & default_color(k,3)==curr_color(:,3));
Or an equivalent BSXFUN approach.
A simple "setdiff(default_color, curr_color, 'rows')" would reduce the code complexity also.
Instead of using the DefaultAxesColorOrder, you could use the ColorOrder of the actual axes object.



Simplified the way the color was determined thanks to Jan's suggestions.

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video