Link to home
Start Free TrialLog in
Avatar of Daniele Questiaux
Daniele QuestiauxFlag for Australia

asked on

reseting plot color order and line style manually?

Hello,
I was wondering does anyone know how to reset the color order and line style manually in matlab?
I know each time you call high-level functions like 'plot' and 'plot3' it resets them automatically (provided you didn't do a 'hold on' beforehand) but how do you do this manually?
I'm NOT trying to set a new color order or line style, I just want to reset them so that my next call to 'plot' starts at the beginning of the current color order and line style lists again and continues.

Thanks in advance.
Avatar of masheik
masheik
Flag of India image

You can save original orders and restore them later. Use 0 as the first argument for the current session, or gcf for current figure.
% save original settings
original_color_order=get(0,'DefaultAxesColorOrder');
%
% do something
%
% and reset
set(0,'DefaultAxesColorOrder',original_color_order);

Open in new window

Avatar of Daniele Questiaux

ASKER

Hi yuk99,
Thanks for the reply. I tried that method before but the only problem was as soon as I resetted, I would also lose my current plots.

In other words, what I was trying to do was only reset the color order/line style back to the beginning while retaining my current plots so the next plot I do goes on the same figure together with my previous plots. Sorry for the long sentence.

Thanks again.
Danièle
Would you show here an example of code you are using? (Please make it as simple as possible just to show the concept.) Do you add new axes or new plot on the same axes?
I'm adding a new plot to the same axis. The following is some semi-pseudo code of what I'm trying to do.
So from the code below, plot(x_1 , y_1) and plot(x_3 , y_3) will be the same color and line style and plot(x_2 , y_2) and plot(x_4 , y_4) will be the same color and line style, etc.
I'm not setting my own color order or line style so I won't know what the order is. I just want to reset the color order and line style lists current being use by Matlab.

Thanks again.
Danièle
myFig = figure;
hold all;
plot(x_1 , y_1);
plot(x_2 , y_2);
% ... etc.
% reset color order and line style
plot(x_3 , y_3);
plot(x_4 , y_4);
% ... etc.
hold off;
% ... etc.

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of yuk99
yuk99
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks yuk99! Your method works perfectly. Too bad Matlab doesn't have a distinct variable in gca that you could reset back to 1 or something, that would have made it more convenient.
Thanks again.
To bad there's no particular variable in gca that you could just reset back to 1  :(
Well, it's Matlab's problem, not mine to get B. I gave you working workaround. But it's ok, thank you anyway.