Solved

reseting plot color order and line style manually?

Posted on 2009-04-08
9
2,425 Views
Last Modified: 2013-11-25
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.
0
Comment
Question by:daniques
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 9

Expert Comment

by:masheik
ID: 24094925
0
 
LVL 15

Expert Comment

by:yuk99
ID: 24097148
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

0
 

Author Comment

by:daniques
ID: 24103038
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:yuk99
ID: 24103240
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?
0
 

Author Comment

by:daniques
ID: 24103301
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

0
 
LVL 15

Accepted Solution

by:
yuk99 earned 500 total points
ID: 24103918
Ah, I understand. At some point for the next plot you want to start over from the 1st color in colororder, or 1st linestyle in linestyleorder.
Well, if you know how many colors you already used (let's say N, you can setup a counter), you can skip the rest with the code below. In the same way it can be done for 'LineStyleOrder'.

numberofcolors=size(get(gca,'ColorOrder'),1);
for i=1:numberofcolors-mod(N,numberofcolors)
    plot(NaN,NaN)
end

Open in new window

0
 

Author Comment

by:daniques
ID: 24104332
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.
0
 

Author Closing Comment

by:daniques
ID: 31567911
To bad there's no particular variable in gca that you could just reset back to 1  :(
0
 
LVL 15

Expert Comment

by:yuk99
ID: 24106036
Well, it's Matlab's problem, not mine to get B. I gave you working workaround. But it's ok, thank you anyway.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
FizzBuzz challenge 9 87
countHi challenge 25 194
wordappend challenge 8 247
Zip Folders Using Chilkat Routines 1 86
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question