Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How can I get more colors with the plot command?

Subject: How can I get more colors with the plot command?

From: James B. Riley

Date: 18 Nov, 1997 15:16:06

Message: 1 of 7

Is there any way to get more colors in the plot
command than just blue, green, red, cyan, magenta
yellow, black, and white?

I know that plot3 and some of the other 3 dimensional
plotting functions use colormaps, but plot seems to be
limited to just the colors I've listed above.

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

--
James B. Riley
riley@ll.mit.edu
MIT Lincoln Laboratory

Subject: How can I get more colors with the plot command?

From: C. Thompson

Date: 18 Nov, 1997 21:58:49

Message: 2 of 7

To get more control, (at a loss of absolutely easy plots) start using
graphics handles. At the simplest, to still be able to use the plot
command,
try (with x's and y's of course being whatever you want)

>> HA=plot(x1,y1,x2,y2)

In the plot command, plot will output HA, the "handles" for each of
the lines you plotted, in my example above, which plots two lines,
HA is a vector of two "handles"
>> HA
HA =
   62.0001
   63.0001

Now you can set a bunch of properties of either of those two
lines without replotting or messing around with anything else.
Usually it works more reliably to change the properties of
one line at a time, i.e. the line HA(1) or the line HA(2)
Do something like get(HA(1)) or set(HA(1)) to see all the properties
that you can change, and what they are now. To change the colors
to arbitrary use a RGB type notation [1 .6 0] is orangish, for example
Note RGB values must be between 0 and 1.

>> set(HA(1),'color',[1 0.6 0]

And the first line x1,y1 will change to orange.
The old notation, 'w', 'b', etc will also work, as in

>> set(HA(1),'color','b')

If you start wanting absolute control over everything, you'll need
to start messing around with graphics handles logic.

Carol Thompson
Northern Illinois University


James B. Riley <riley@ll.mit.edu> wrote in article
<64sso8$ld0@llnews.ll.mit.edu>...
> Is there any way to get more colors in the plot
> command than just blue, green, red, cyan, magenta
> yellow, black, and white?
>
> I know that plot3 and some of the other 3 dimensional
> plotting functions use colormaps, but plot seems to be
> limited to just the colors I've listed above.
>
> I have an application where I need to plot
> dozens of lines, each with a different color.
>
> --
> James B. Riley
> riley@ll.mit.edu
> MIT Lincoln Laboratory
>
>
>

Subject: How can I get more colors with the plot command?

From: bill-driscoll@ti.com (Bill Driscoll)

Date: 18 Nov, 1997 23:02:24

Message: 3 of 7

In article <64sso8$ld0@llnews.ll.mit.edu>, riley@ll.mit.edu says...
>
>Is there any way to get more colors in the plot
>command than just blue, green, red, cyan, magenta
>yellow, black, and white?
>
>I know that plot3 and some of the other 3 dimensional
>plotting functions use colormaps, but plot seems to be
>limited to just the colors I've listed above.
>
>I have an application where I need to plot
>dozens of lines, each with a different color.
>
>--
>James B. Riley
>riley@ll.mit.edu
>MIT Lincoln Laboratory
>
>

If you want to use colormap colors you can do something like:

colormap('jet(32)');
map=colormap;
figure;
set(gcf,'DefaultAxesColorOrder',map);
plot( [1 10], [(1:32)' (1:32)']);

HTH, Bill D.

Subject: How can I get more colors with the plot command?

From: Loren Shure

Date: 19 Nov, 1997 13:09:47

Message: 4 of 7

If you know the rgb values for the other colors you also want cycle
through, you can set the axes property 'colororder'. Specify an N x 3
array of values between 0 and 1 (the rows represent rgb values) for N
colors.

--Loren

James B. Riley <riley@ll.mit.edu> wrote in article
<64sso8$ld0@llnews.ll.mit.edu>...
> Is there any way to get more colors in the plot
> command than just blue, green, red, cyan, magenta
> yellow, black, and white?
>
> I know that plot3 and some of the other 3 dimensional
> plotting functions use colormaps, but plot seems to be
> limited to just the colors I've listed above.
>
> I have an application where I need to plot
> dozens of lines, each with a different color.
>
> --
> James B. Riley
> riley@ll.mit.edu
> MIT Lincoln Laboratory
>
>
>

Subject: How can I get more colors with the plot command?

From: Maria

Date: 5 Mar, 2013 20:56:08

Message: 5 of 7

Any color can be chosen from an [R G B] list.
I came up with a list of some of the colours you could use:
[1 1 0] Yellow
[0 0 0] Black
[0 0 1] Blue
[0 1 0] Bright green
[0 1 1] Cyan
[1 0 0] Bright red
[1 0 1] Pink
[1 1 1] White
[0.9412 0.4706 0] Orange
[0.251 0 0.502] Purple
[0.502 0.251 0] Brown
[0 0.251 0] Dark green
[0.502 0.502 0.502] Gray
[0.502 0.502 1] Light purple
[0 0.502 0.502] Turquoise
[0.502 0 0] Burgundy
[1 0.502 0.502] Peach

Basically, I went on Paint to identify colours that I wanted, then I divided each of the RGB values by 255 to get to the vector form that Matlab would use to specify the exact shade.

Below is an example code that shows what those colours would look like, and how I came to their values.


x=[1:17
    1:17];

H = bar(x)
xlim([0.5 1.5]);

a=[1 1 0
    0 0 0
    0 0 1
    0 1 0
    0 1 1
    1 0 0
    1 0 1
    1 1 1
    240/255 120/255 0
    64/255 0 128/255
    128/255 64/255 0
    0 64/255 0
    128/255 128/255 128/255
    128/255 128/255 1
    0 128/255 128/255
    128/255 0 0
    1 128/255 128/255]

for i=1:17
    set(H(i),'EdgeColor',a(i,:),'faceColor',a(i,:));
end

I hope this helps!

"James B. Riley" <riley@ll.mit.edu> wrote in message <64sso8$ld0@llnews.ll.mit.edu>...
> Is there any way to get more colors in the plot
> command than just blue, green, red, cyan, magenta
> yellow, black, and white?
>
> I know that plot3 and some of the other 3 dimensional
> plotting functions use colormaps, but plot seems to be
> limited to just the colors I've listed above.
>
> I have an application where I need to plot
> dozens of lines, each with a different color.
>
> --
> James B. Riley
> riley@ll.mit.edu
> MIT Lincoln Laboratory
>
>

Subject: How can I get more colors with the plot command?

From: Steven_Lord

Date: 5 Mar, 2013 21:55:31

Message: 6 of 7



"Maria " <maria.short@exactearth.com> wrote in message
news:kh5m58$rmd$1@newscl01ah.mathworks.com...
> Any color can be chosen from an [R G B] list. I came up with a list of
> some of the colours you could use:

*snip*

FYI there's a tool called UISETCOLOR that allows you to interactively select
the color you want and determine its RGB triplet.

http://www.mathworks.com/help/matlab/ref/uisetcolor.html

You could generate a handful of colors and store them as small functions (or
even anonymous functions) for future use.

function rgb = pink
% Your definition of 'pink' may vary
rgb = [255 158 210]./255;

You could use this as:

plot(1:10, 1:10, 'LineWidth', 20, 'Color', pink() )

The extra parentheses aren't needed if you're calling the pink function, but
they are if you create an anonymous function named pink and want to use it
there.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: How can I get more colors with the plot command?

From: Paul Mennen

Date: 10 Mar, 2013 08:14:06

Message: 7 of 7

>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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us