Ways to control color and line style
1. LineStyleCyclingMethod
In MATLAB R2023a or later, the LineStyleCyclingMethod property of axes allows you to control how to cycle through line styles and colors when adding objects to axes. Options include This example combines 2 line styles with 3 colors
colors = [1 0 0; 0 0 1; 0 1 0];
ax1.LineStyleOrder = styles;
ax1.LineStyleCyclingMethod = 'aftercolor';
plot(0:.1:1, rand(1,11)+(1:6)')
ax2.LineStyleOrder = styles;
ax2.LineStyleCyclingMethod = 'beforecolor';
plot(0:.1:1, rand(1,11)+(1:6)')
ax3.LineStyleOrder = styles;
ax3.LineStyleCyclingMethod = 'withcolor';
plot(0:.1:1, rand(1,11)+(1:6)')
title(tcl, 'LineStyleCyclingMethod')
2. Use LineStyleOrder and ColorOrder
ax.LineStyleOrderIndex = ax.LineStyleOrderIndex;
ax.LineStyleOrder = {'-o','-+','-*','-x','-s','-d','-v','->','-h','-^'};
ax.ColorOrder = [1 0 0; 0 1 0; 0 0 1; 0 1 1; 1 0 1];
plot(0:.1:1, rand(1,11)+i, 'DisplayName', ['Line ', num2str(i)]);
legend('Location','bestoutside')
For additional flexibility if variation, see the SeriesIndex property of line objects. 3. Manually set line and color properties
The demo shows how to list various markers, colors, and linestyles to be assigned to an infinite number of line objects. The properties are selected circularly so there is no requirement for the length of each property list. If the length of each property differ, you will have more combinations of markers, colors, and linestyles. Unlike option 1, the color, linestyle, and marker properties can vary on each iteration.
markers = {'o','+','*','s','d','v','>','h'};
colors = {'b','g','r','k','c','m'};
linestyle = {'-','--','-.',':'};
getprop = @(options, idx)getFirst(circshift(options,-idx+1));
plot(0:.1:1, rand(1,11)+j,...
'Marker',getprop(markers,j),...
'color',getprop(colors,j),...
'linestyle',getprop(linestyle,j),...
'DisplayName', ['Line ', num2str(j)]);
legend('Location','bestoutside')
4 Manually set line and color properties
The attached m-files contains a function lineprops(idx) that returns a set a marker, linestyle, and color name-value pairs based on the index value idx. There are 156 combinations.
Demo:
plot(0:.1:1,rand(1,11)+i, nameval{:}, 'LineWidth', 1.5)
legend('Location','BestOutside')