File Exchange Pick of the Week

Our best user submissions

Colors for Your Multi-Line Plots

Jiro's pick this week isVARYCOLORby Daniel Helmick. Have you ever had to plot many lines on a single graph and you had to construct additional set of colors to augment the 8 built-in colors? You may have to come up with a good set of colors that span a wide range of the spectrum. Daniel'svarycolorwill give you that color set with a single command. Let's say I'm going to plot 50 lines. I can get the color matrix like this:
ColorSet = varycolor(50);
I can either index into this color matrix and use it as myColorproperty forplot:
plot(rand(10,1), 'Color', ColorSet(1,:))
Or set it as the newColorOrderproperty of an axes. Now, my subsequent plots will follow the new color order. (Be sure to usehold all来preserve the color order.)
set(gca,'ColorOrder', ColorSet); holdall;form = 1:50 plot([0 51-m], [0 m]);end
When I have this many lines, I often wonder what the best way to put a legend is. I can simply add the default legend:
legendshowLocationNorthEastOutside
But this is quite impractical. Instead, I can use the color matrix that I just created and use that in my color bar.
legendoffset(gcf,'Colormap', ColorSet); colorbar
自从我适当地选择颜色的数量to be the same as the number of lines, the colormap scale corresponds to the line number. Line 1 is green and line 40 is red. As a bonus, take a look at Loren's blog onPlotting with Style来learn about other ways to customize the line style.CommentsTell usherehow you customize your visualizations to convey your ideas as clearly as possible. Do you use colors, line styles, or markers? Or maybe some combinations.

Published with MATLAB® 7.6

|
  • print
  • send email

Comments

To leave a comment, please clickhere来sign in to your MathWorks Account or create a new one.