The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How can I get more colors with the plot command?
Replies: 2   Last Post: Mar 10, 2013 4:14 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Paul Mennen

Posts: 311
Registered: 12/7/04
Re: How can I get more colors with the plot command?
Posted: Mar 10, 2013 4:14 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

>I have an application where I need to plot
>dozens of lines, each with a different color.
>James B. Riley

Hi James.

As C. Thomson pointed out, with plot you can get much finer control over the trace properties (including color of course) by getting the trace handles from the plot command return values and then using the handle graphics commands.

On the other hand, if you don't want to get into all the handle graphics commands, I have written an alternative to plot() and plotyy() that you can find on the file exchange. (Just search for "plt"). Because of the large number of options to the plt command, you rarely if ever have to resort to learning the handle graphics commands for just about any 2D plotting problem. Another advantage is that all these options are clearly explained in one document (with examples!) so you don't have to be scurrying around the whole Matlab documentation for the various handle graphics commands. In the unlikely event you don't find the parameter you need in the plt documentation, I'm usually around to answer such questions.

Back to your problem of using colors to distinguish a large number of traces ... turns out I've spent considerable effort on that problem. My research showed that people can distinguish (based on color alone) the difference between far more traces with far less effort when a black plotting background is used even when picking the optimal trace colors (which are different for each background color choice). I believe the reason has to do with the interaction between color saturation and acceptable contrast.

If you are not using plt, but still want to try out this idea, try a dark plotting background, and use these colors for your first 34 traces:

0 1 0; 1 0 1; 0 1 1; 1 0 0; .2 .6 1;
1 1 1; 1 .6 .2; 0 0 1; 1 .2 .6; .2 1 .6;
.6 1 .2; .6 .2 1; 1 1 0; 0 .6 0; .6 0 .6;
0 .6 .6; .6 .6 0; .7 .7 .7; .6 0 0; .2 .2 .7;
.5 .5 .5; .7 .2 .2; .2 .7 .2; 0 0 .6; .3 .3 .3;
0 .9 .4; 0 .4 .9; .9 .4 0; .4 .9 0; .9 0 .4;
.4 0 .9; .8 .5 .5; .5 .8 .5; .5 .5 .8;

I have chosen those colors to be as easily distinguished as possible using several different monitors and surveying the responses of several test subjects. Of course the colors slowly get somewhat more difficult to distinguish as you go down in the table. My plt plotting routine defaults to using these colors. If there are more than 34 traces, the next 34 use the same set of colors multiplied by .75, and if there are more than 68, it scales it again by another factor of .75. It's an art form however, so I couldn't really argue with you if you decided that different colors should be used or that the order for the colors that I have chosen was sub-optimal. To see an example with 50 traces, try the "plt50.m" demo program included with plt. Note that the trace labels in the legend appear using the same color as its associated trace. There are options in the command line to include the line
style in the legend as well which is particularly helpful when you are also using different line styles to help distinguish the various traces. (Note that one of the demo examples does use a white plotting background, and in fact you can use any color you want for that, as well as for the grid lines, axes, axis labels, cursors, figure background, etc).

~Paul Mennen

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.