Hi guys, I love the new default colors in 2014b. I would, however, be able to use then to color lines out of order sometimes. Any idea what their RGB values are?
thanks -Alex

 Réponse acceptée

Mike Garrity
Mike Garrity le 28 Oct 2014
The simplest way is the ColorOrder property on the axes.
get(gca,'ColorOrder')
To get the values without an axes, you can do this:
get(groot,'DefaultAxesColorOrder')

3 commentaires

Alexandre Laurin
Alexandre Laurin le 28 Oct 2014
Thanks Mike!
arthur Le Gall
arthur Le Gall le 23 Août 2017
Hi Alex very nice question, it was very useful for me.
Michael Sonnenberg
Michael Sonnenberg le 24 Avr 2020
Agreed, thanks for the question and answer.

Connectez-vous pour commenter.

Plus de réponses (4)

Star Strider
Star Strider le 28 Oct 2014
The new default colormap is called ‘parula’. To get 8 RGB values of it, use the colormap function:
cmp = colormap(parula(8));
to return them in the ‘cmp’ variable. To get more values, change the ‘8’ to the number you want.

1 commentaire

Alexandre Laurin
Alexandre Laurin le 28 Oct 2014
Thanks for the answer, Star Strider. I should have been clearer. I was looking for the RGB of the default colors when plotting lines or 2-D graphs.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 28 Oct 2014

2 votes

To change the default color order, see my demo, attached below the image.
A variety of color orders are presented for you to pick from or you can adapt it to customize it completely to the exact colors you want.

3 commentaires

Bruno Melo
Bruno Melo le 20 Juin 2019
Modifié(e) : Bruno Melo le 20 Juin 2019
Nice. Thank you for proving us the code.
Ageb Kara
Ageb Kara le 22 Jan 2020
Dear,
I am trying to find the best way to plot the spectrum (x,y), where x-wavenegths, y=intesity, in a way to fill 2D graph with the corresponding color of the wavelength?
How would you suggest to do this?
Kindlydf.png
Image Analyst
Image Analyst le 23 Jan 2020
Ageb, I'd probably create an image and use image() or imshow() to display it. I'd make each column from the bottom of the image up to the black curve be a color map value. Use jet() or hsv() to create the colormap. Start a new thread if you still need help. And say how many columns you'd like the image to have (can be as many as how many columns your screen has).

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 28 Oct 2014

1 vote

See my attached demo, below the image.
You can select several standard demo images and several standard colormaps. The images are displayed with the colormap and the RGB curves for the color map are plotted.

11 commentaires

Hrefna
Hrefna le 11 Nov 2014
Hi,
When I plot lines I see red colors which do not exist in the parula colormap. Where do they come from? I want to plot 8 lines with different colors, but the default colororder only has 7 entries. Help?! :)
Image Analyst
Image Analyst le 11 Nov 2014
Attach a screenshot. I don't see any reason why the parula colormap would have any unexpected colors in it.
To get more than the standard number of colors in the default colormap, see my demo below where I increased it to 20 custom colors. There is an m-file attached to that answer that tells you how to do it.
Hrefna
Hrefna le 11 Nov 2014
Modifié(e) : Hrefna le 11 Nov 2014
Hi, here's what I'm talking about:
That pretty red and purple aren't in the parula colormap (see colorbar next to your image of the person with the camera). Where are they from? :)
Here's the code:
close all; clear all;
x = 0:0.01:3.14/2;
f = repmat([1:7]', 1, length(x));
y = cos(2*pi*repmat(x, size(f,1), 1)./f);
figure(1); clf;
plot(x,y,'linewidth', 1.5);
Sorry, my answer was incomplete.
My problem is that when I use the parula colormap to do lines, I don't get reds, just blues, greens and orange/yellow. See the below image
It seems like the default colors are drawing from some other colormap than parula...?!?!
(And yes, I know I can get more colors using parula(numberofcolors) :) )
Here's the code I used:
close all; clear all;
x = 0:0.01:3.14/2;
f = repmat([1:7]', 1, length(x));
y = cos(2*pi*repmat(x, size(f,1), 1)./f);
colorMatrix = parula(size(f,1));
figure(1);
subplot(2,1,1)
plot(x, y,'linewidth', 1.5);
title('Default Matlab Lines')
subplot(2,1,2)
for nColor = 1:size(f,1)
plot(x, y(nColor,:), 'color', colorMatrix(nColor,:), 'linewidth', 1.5);
hold on;
end
title('Parula Lines')
Ah, the ColorOrder and the Colormap are two different things.
The Colormap is what is used to convert color data (typically named CData) into colors. This is used by all of the objects which have CData such as surface and image.
The ColorOrder is used by charts which don't have CData, such as plot.
The reason there are two is that the Colormap is designed to display data which interpolates through a range of data values and clearly show the relative values of the CData. On the other hand, ColorOrder is designed for a small number of chart "series" which need to be easy to distinguish. Because of this difference, colormaps like parula tend to be "smooth" and the default colororder is very discontinuous. The colormaps tend to make bad colororders because its hard to tell the different series apart.
But you can use parula as a ColorOrder if you would like. You would do it like this:
ax=gca
ax.ColorOrder = parula(12)
hold on
plot(magic(7))
Note that the "hold on" is important. If you don't have that, then the first thing plot is going to do is reset the ColorOrder. Also, I asked parula to only give me 12 colors because if I had used its default I'd have only sampled the blues at the bottom.
Hrefna
Hrefna le 11 Nov 2014
That explains so much! Thank you!
I just wish matlab would include a 'muted jet' colormap, i.e. the entire rainbow of colors, but muted like the new line colors. Sigh.
You could play around with things like this:
colormap(1/2 + jet*1/2)
or
colormap(jet .^ .25)
The colormap entries are just RGB triples in the range [0 1]. You're free to fold, spindle, and mutilate them any way you'd like.
Another way to get muted rainbows is to use the hsv2rgb function. It takes 3 values. The first is a "hue". You want that to be a ramp from 0 to 1. The other two are the "saturation" and "value". Making saturation less than 1 will mute your colors.
t = linspace(0,1,64)';
s = 1/3 + zeros(64,1);
v = ones(64,1);
colormap(squeeze(hsv2rgb(t,s,v)))
Hrefna
Hrefna le 11 Nov 2014
Oh dear. You've just created a monster! ;)
Tuned the above to get what I was looking for. Thank you again! :)
t = linspace(0,1,lineCount)';
s = 1/2 + zeros(lineCount,1);
v = 0.8*ones(lineCount,1);
lineColors = colormap(squeeze(hsv2rgb(t,s,v)))
ax=gca
ax.ColorOrder = lineColors;
Mike Garrity
Mike Garrity le 11 Nov 2014
> Oh dear. You've just created a monster! ;)
Creating graphics monsters is the best part of my job!
Hrefna
Hrefna le 12 Nov 2014
...if only you could help me tame the oversized space-hogging legend box in a simple way, and I'd be set until the next update of Matlab... :) :) (See this question .)

Connectez-vous pour commenter.

EvilDrW
EvilDrW le 24 Oct 2017
you want the command "lines"...
lineColors = lines(8)
the methods above that use
get(gca, 'ColorOrder')
seem to only give you the first 7 line colors, where the lines command allows you to specify the number of colors you want and also doesn't rely on having an active axis to get your rgb color values.

1 commentaire

Stephen23
Stephen23 le 21 Juin 2019
Modifié(e) : Stephen23 le 21 Juin 2019
"to only give you the first 7 line colors"
There are only seven colors in the default line ColorOrder, so you can't get more.
"...where the lines command allows you to specify the number of colors you want"
Not really. You can certainly return a colormap of the size that you request, but the colors will repeat if you request more colors than the line ColorOrder has, so you will not get more than seven unique colors (assuming the default line ColorOrder of seven colors).
You can check this quite easily by looking at the lines code, or with a simple example:
>> lines(8) % only 7 colors in the ColorOrder
ans =
0 0.447 0.741 % duplicate!
0.85 0.325 0.098
0.929 0.694 0.125
0.494 0.184 0.556
0.466 0.674 0.188
0.301 0.745 0.933
0.635 0.078 0.184
0 0.447 0.741 % duplicate!

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by