How do I force each line I create to be created in the standard color order?

1 view (last 30 days)
When I use PLOT to draw multiple lines at once, they are drawn in the default axes color order:
figure
t=0:0.1:2*pi;
plot(t,sin(t),t,cos(t),t,sin(t).*cos(t))
However, if I plot them separately and use HOLD ON, they are all drawn in the same color, which is the first color in the color order:
figure
t=0:0.1:2*pi;
plot(t,sin(t))
hold on
plot(t,cos(t))
plot(t,sin(t).*cos(t))
How do I force all of my plotted lines to obey the color order?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 10 Apr 2023
Edited: MathWorks Support Team on 13 Apr 2023
This enhancement has been incorporated in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
There is no function in MATLAB that can force all lines to obey the axes color order.
To solve this problem, you can try the user-contributed file, "createlineincolororder.m" from MATLAB Central File Exchange:
NOTE: User-contributed files are not tested by MathWorks, and are therefore not fully supported.
An example for using the function can be found in the help for the function, as well as in the link above.
Note that "createlineincolororder.m" makes use of the 'ColorOrder' property of an AXES object. That property can be queried and set to view or modify the color order. For example, here is the default color order:
get(0,'defaultaxescolororder')
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
For more information on Handle Graphics and using GET and SET, please see the following resources:
Handle Graphics Object Properties

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!