Multiple plots using a method on single axis?

1 view (last 30 days)
I have a method that plots an array of data onto an axes in my GUI. I want to be able to call this method in a for loop and all the data that is plotted be on the same axes and not reset every time the method is called. Is this possible?

Accepted Answer

dpb
dpb on 29 Jul 2015
Sure, just set hold on for the figure after the first plot...
NB: To cycle colors/linestyles you'll have to increment and pass a color/linestyle argument for each; otherwise Matlab starts counting over from the beginning of the default order. I think this is a glaring weakness in the controllability as it's such a common desire to add incrementally as opposed to always having all the data that can make a single call in which case the colors/linestyles do cycle automagically. But, several requests for it as an enhancement over the years went unheeded so I've given up... :(
  4 Comments
Walter Roberson
Walter Roberson on 29 Jul 2015
You only need "hold on" once, but it does not hurt to call it extra times.
Duane: Starting from R2014b, "hold on" does cycle colors between successive plot calls. See http://www.mathworks.com/help/matlab/graphics_transition/why-are-plot-lines-different-colors.html
dpb
dpb on 29 Jul 2015
Edited: dpb on 30 Jul 2015
While the extra hold on operation "doesn't hurt" there's just something about extra operations that aren't needed that seems reasonable to avoid. I've often wondered (but never actually tried to measure) whether it's more expensive to have hold on every pass inside a loop such as OP's or to do the test on a counter or a flag and branch. If it's at all convenient I'm anal enough that I'll rearrange the loop and move the initial case and the hold command to precede the loop to avoid both. It's just ugly, no matter what way you go at it.
And on the color cycling, just think--only 25+ yr since my first enhancement request for it!!! :)
I've not yet tried one of the later releases given all the comments on how much more memory and processor power is required over 2K 12b. Is it still so, I can only put 4GB in this machine which had to do to be able to use this version.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 29 Jul 2015
Use
hold on
if you want to have all of the objects appear together on the same axes.

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!