Colors and Line Styles Used for Plotting

The ColorOrder and LineStyleOrder properties on the axes control the colors and line styles for multiline plots.

The axes increments the line style after using all of the colors in the ColorOrder property. It then uses all the colors again with the second line style, and so on.

Starting in R2019b, you can change the colors and line styles of an existing plot by setting the ColorOrder and LineStyleOrder properties. For example, plot nine sine waves using the default color order and line style order.

x = linspace(0,7);
y = ones(length(x),9);
for i = 1:9
    y(:,i) = sin(x-i/5)';

Change the color order to orange, purple, and dark green. Then change the line styles to the solid, dashed, and dotted lines.

ax = gca;
ax.ColorOrder = [1 0.5 0; 0.5 0 1; 0 0.5 0.3];
ax.LineStyleOrder = {'-','--',':'};

You can also change the color order by calling the colororder function. When you use this function, you can specify colors as RGB triplets, hexadecimal color codes, or as color names. For example, change the color order in the plot to red, green, and blue.


See Also