Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default MATLAB Color Order?

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?

like image 212
Toad22222 Avatar asked Oct 15 '14 00:10

Toad22222


People also ask

How are colors represented in MATLAB?

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.

What is the default colormap MATLAB?

If you have not specified a different default value, then the default colormap is parula .


2 Answers

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:

  1. Pure blue
  2. A lighter shade of green
  3. Pure red
  4. A mixture of green and blue, which is cyan
  5. A mixture of red and blue, which is magenta
  6. A mixture of red and green which is yellow
  7. A light mixture of red, green and blue, which looks like a dark gray.

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:

enter image description here

Running this code again in MATLAB R2015a, this is what I get:

enter image description here


Alternatively, you can always use a legend that delineates what histogram comes from which data.

like image 111
rayryeng Avatar answered Sep 23 '22 16:09

rayryeng


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:

enter image description here

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).

like image 26
Dev-iL Avatar answered Sep 24 '22 16:09

Dev-iL