MATLAB Answers

0

Why are plot lines colored differently in MATLAB R2014b compared to previous releases of MATLAB?

I am trying to plot multiple lines using a single plot command. For example, the command that I use is :
 
plot(rand(5))
The line colors that I see in MATLAB R2014b are different from MATLAB R2014a. Why is that so?

Products


Release

R2014b

1 Answer

Answer by MathWorks Support Team on 10 Apr 2015
 Accepted Answer

The behavior seen in MATLAB R2014b is due to a new color order. The details are explained below:
Starting in R2014b, MATLAB® graphics has a new color order that determines the colors used in plots. This is the color order introduced in R2014b and the RGB triplet values that define the colors:
         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
 
This is the color order in R2014a and earlier.
 
         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
The 'ColorOrder' property of the axes contains the color order. To change the color order, set a different default value for the 'ColorOrder' property. For example, this code sets the default color order to the colors used in previous releases.  An enhancement request has been submitted to make it easier to go back to the previous release color order.
 
co = [0,0,1;
     0,0.5,0;
     1,0,0;
    0,0.75,0.75;
    0.75,0,0.75;
    0.75,0.75,0;
    0.25,0.25,0.25];
set(groot,'defaultAxesColorOrder',co);
The hold Command Cycles Through Colors
In previous releases, the 'hold on' command does not retain the current color so new plots added to the axes start from the beginning of the color order. Visually, this means that new plots use the same initial color. Starting in R2014b, the 'hold on' command retains the current color so that new plots added to the axes use the next colors in the color order.
For example, this code displays three lines using the 'hold on' command.
 
plot(1:10);
hold on
plot(11:20);
plot(21:30);
hold off
In R2014a and earlier, the lines use the first color from the color order.
Starting in R2014b, the lines cycle through the color order.
If you want to plot multiple lines using the same color in R2014b, then set the Color property for each line to the same value. For example, plot the three lines using the same RGB triplet color value.
 
rgbcolor = [0 0.447 0.741];
plot(1:10,'Color',rgbcolor);
hold on
plot(11:20,'Color',rgbcolor);
plot(21:30,'Color',rgbcolor)
hold off
 
 

  0 Comments

Sign in to comment.