I have a plot with two histograms. However, it is difficult to tell which histogram on the plot is coming from the first set of data and which graphs the second set of data. There is a different colored line for each histogram: one is blue, and the other is green. Does the default MATLAB 'ColorOrder'
vary between devices? If not - what is the order?
In a truecolor image, every image pixel has three values associated with it: the red, green, and blue components. You represent a truecolor image in MATLAB with a three-dimensional array of size M-by-N-by-3.
If you have not specified a different default value, then the default colormap is parula .
Good question! There is a default colour order for MATLAB. Take note that versions before R2014b, the default colour order for MATLAB uses the jet colour map. In the jet colour map, the first plot is blue, followed by the second plot being green. For versions after R2014b, this follows the parula colour map, where the first plot would be a lighter blue followed by the second plot being a copper orange of sorts. If you actually want to know what the colour order is for your plot, make sure the plot is open in MATLAB, then do the following:
get(gca,'colororder')
This will return a 2D matrix where each row gives you the proportion of red, green and blue for each plot that you produce. On my machine at the time of this post when I was running MATLAB R2013a and with Mac OSX 10.9.5, this is what I got:
>> get(gca,'colororder') ans = 0 0 1.0000 0 0.5000 0 1.0000 0 0 0 0.7500 0.7500 0.7500 0 0.7500 0.7500 0.7500 0 0.2500 0.2500 0.2500
Each row gives you the red, green and blue values for a particular colour. The first row denotes the first colour to go on the plot, followed by the second row denoting the second colour and so on.
As such, the above colour order is:
Currently (March 10th, 2016), I am using MATLAB R2015a and this is the colour map I get:
>> get(gca,'colororder') ans = 0 0.4470 0.7410 0.8500 0.3250 0.0980 0.9290 0.6940 0.1250 0.4940 0.1840 0.5560 0.4660 0.6740 0.1880 0.3010 0.7450 0.9330 0.6350 0.0780 0.1840
The RGB tuples in this case are slightly more complex and so it's hard to infer what they are by just looking at the colours.
As an additional bonus, we can create an image that visualizes these colours for you. Assuming you have the image processing toolbox, this is the code I wrote to visualize those colours for each plot you place in your figure.
colours = permute(get(gca, 'colororder'), [1 3 2]); colours_resize = imresize(colours, 50.0, 'nearest'); imshow(colours_resize);
Here's what I got for MATLAB R2013a:
Running this code again in MATLAB R2015a, this is what I get:
Alternatively, you can always use a legend
that delineates what histogram comes from which data.
There exists a colormap for this specific purpose - lines
(Introduced before R2006a). Here's what lines.m
says:
%LINES Color map with the line colors. % LINES(M) returns an M-by-3 matrix containing a "ColorOrder" % colormap. LINES, by itself, is the same length as the current % colormap. If no figure exists, MATLAB uses the length of the % default colormap.
If you open the documentation of lines
, you can see a preview image that looks very much like what appears in rayryeng's answer:
Thus, as long as you're using the default colormap
, to know the colors of the first n
lines, all you need to do is call lines(n)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With