Code covered by the BSD License  

Highlights from
Find unused plot color

5.0

5.0 | 1 rating Rate this file 9 Downloads (last 30 days) File Size: 1.67 KB File ID: #37137
image thumbnail

Find unused plot color

by

 

12 Jun 2012 (Updated )

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

| Watch this File

File Information
Description

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.

Required Products MATLAB
MATLAB release MATLAB 7.10 (R2010a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (3)
21 Jun 2012 Jan Simon

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.

13 Jun 2012 Deborah

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

12 Jun 2012 Jan Simon

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 "...in 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.

Updates
20 Jun 2012

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

Contact us