Do figures have to be active to add plots to them?

Hi Guys, This is the situation, I create 4 fill plots using and return there respective axis handles using:
figure('OuterPosition',[1 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2])
SpecH = myFill(f1,specMat,'Frequency Spectrum');
figure('OuterPosition',[scrsz(3)/2 scrsz(4)/2 scrsz(3)/2 scrsz(4)/2])
AvgH = myFill(f2,bandAVGsMat,'Band Average');
figure('OuterPosition',[1 scrsz(4)/36 scrsz(3)/2 scrsz(4)/2])
VarH = myFill(f2,bandVarsMat,'Band Variance');
figure('OuterPosition',[scrsz(3)/2 scrsz(4)/36 scrsz(3)/2 scrsz(4)/2])
PwrH = myFill(f2,pwr2ResMat,'Band Power ratio to the fundermental');
I then wish to put a new line on each fill plot as I pass through a loop. I do this using:
hold on
plot(SpecH,f1,dataStoreT(i,:),'g','LineWidth',2)
plot(AvgH,f2,bandAVGsT,'g','LineWidth',2)
plot(VarH,f2,bandVarsT,'g','LineWidth',2)
plot(PwrH,f2,pwr2ResT,'g','LineWidth',2)
hold off
When I run this; one of the plots, the one which is currently active, adds the line no problem. BUT the other three clear the "fill" type plots and just plot the line. I have noticed that this clearing of the old lines only happens to the plots which are not active (and also the active plot seems to always be the second to last one plotted?!..)
So my question is: How do I activate a plot before adding the line and is this necessary or is there some workaround?
Thanks in advance.
Kind Regards,
Tim.

 Réponse acceptée

Walter Roberson
Walter Roberson le 25 Sep 2012

0 votes

The difficulty you are encountering is that "hold on" applies to the current axes, not to all axes.

4 commentaires

Right OK. So I see why the other plots are not updating. But Is there a way to make a plot, which I have the handles to, the current one. Or do I also have to return the figure handles (Not axis handles) from the myFill function? So like:
[axisHandle1,figureHandle1] = myFill(data1)
[axisHandle2,figureHandle2] = myFill(data2)
[axisHandle3,figureHandle3] = myFill(data3)
Then:
figure(figureHandles2)
hold on
plot(axisHandles2,newX2,newY2)
hold off
figure(figureHandles1)
hold on
plot(axisHandles1,newX,newY)
hold off
figure(figureHandles3)
hold on
plot(axisHandles3,newX3,newY3)
hold off
???
Tom
Tom le 25 Sep 2012
Modifié(e) : Tom le 25 Sep 2012
you don't need to set the figure or axes to be current (and in this can you don't need to hold on as there is only one plot?). You can set which axes to plot on in the plot function- it's the first argument
plot(axisHandle,x,y)
you can hold selected axes by using
hold(axisHandle,'on')
or
set(axisHandle,'NextPlot','Add')
This did the trick. Many thanks :)
I see, so I was making the simple hold on command work by activating each figure in turn, where as I could have used:
hold(axisHandle,'on')
Instead. Thanks for your help. :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by