Colors for Your Multi-Line Plots
Jiro's pick this week is VARYCOLOR by 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's varycolor will 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 my Color property for plot:
plot(rand(10,1), 'Color', ColorSet(1,:))Or set it as the new ColorOrder property of an axes. Now, my subsequent plots will follow the new color order. (Be sure to use hold all to preserve the color order.)
set(gca, 'ColorOrder', ColorSet); hold all; for m = 1:50 plot([0 51-m], [0 m]); endWhen I have this many lines, I often wonder what the best way to put a legend is. I can simply add the default legend:
legend show Location NorthEastOutsideBut this is quite impractical. Instead, I can use the color matrix that I just created and use that in my color bar.
legend off set(gcf, 'Colormap', ColorSet); colorbarSince I appropriately chose the number of colors 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 on Plotting with Style to learn about other ways to customize the line style. Comments Tell us here how you customize your visualizations to convey your ideas as clearly as possible. Do you use colors, line styles, or markers? Or maybe some combinations.
- 범주:
- Picks
댓글
댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.