Reset Color Order in MATLAB

This tutorial demonstrates how to reset color order in MATLAB.

Reset Color Order in MATLAB

The color order is used to set the colors for a figure or plot in MATLAB. If the figure or plot doesn’t exist, MATLAB will create a figure and set colors for it.

The color can be customized when calling a plot function or even after calling the plot function. Here is an example of a plot in MATLAB with default colors.

Colors Challenge play now https://p...
Colors Challenge play now https://playingzone.in/game/colors-challenge
plot1 = plot([0 1 2 3],'-r');
hold on
plot2 = plot([1 2 3 4],'--g');
hold off

% Add markers to the plot
plot1.Marker = 'sq';
plot2.Marker = 'o';

Plot with Default Colors

Now let’s see how to change the colors in a plot. See example:

demoaxes = axes;
demoaxes.ColorOrder = [ 0 0 0; 0 0 1; 0 1 0; 1 0 0];
demoaxes.LineStyleOrder = {'-','--'};
hold on
for a = 0:7
    plot([a a+2])
end
hold off

The code above will assign the ColorOrder and LineStyleOrder to the plot. See output:

Plot with Assigned Colors

To reset the color order in MATLAB, we use the set method and set the ColorOrderIndex to 1, which will reset the ColorOrder for a figure or plot. Let’s try to reset the ColorOrder in the above example.

demoaxes = axes;
demoaxes.ColorOrder = [ 0 0 0; 0 0 1; 0 1 0; 1 0 0];
demoaxes.LineStyleOrder = {'-','--'};
%Reset Color Order
set(axes,'ColorOrderIndex',1)
hold on
for a = 0:7
    plot([a a+2])
end
hold off

The ColorOrder is reset for the given plot. See the output:

Reset ColorOrder