axis changes even after "axis equal"
22 views (last 30 days)
Show older comments
I would like to plot a line on an axis without changing the XLim and YLim values. I obviously went through the "axis equal" command (or the ax.XLimMode='manual'; ax.YLimMode='manual';) but this doesn't seems to work.
Where am I doing wrong?
plot(1:10)
% XLim is not [1 10]
axis manual
plot(1:20)
% XLim should be again [1 10], instead it's [0 20] now
it works with
plot(1:10)
% XLim is not [1 10]
hold on
axis manual
plot(1:20)
% XLim should be again [1 10], instead it's [0 20] now
but I don't want to hold previous plots (it's an animation).
A workaround could be to use
ph=plot(1:10)
axis manual
hold on
delete(ph)
plot(1:20)
but I this seems over-complicated to do the simple thing I'm asking to...
I'm working with matlab R2015a
0 Comments
Accepted Answer
Chad Greene
on 13 Apr 2015
If you don't hold the plots, axis limits will be reset every time you call plot. For an animation, you can use hold and either delete plotted objects or change their data. That is,
hold on
h = plot(1:10);
<grab animation frame here>
delete(h)
h = plot(1:20);
and so on. Or you can change the data in h with
set(h,'xdata',1:20,'ydata',1:20)
More Answers (1)
pfb
on 14 Apr 2015
Edited: pfb
on 14 Apr 2015
If I understand this correctly, you want an animation with fixed xlim, but you do not want to set the xdata and ydata (I agree with Chad Greene that this is the way to go, but I understand your commment about your students).
I guess that you're plotting plots in a loop, to form the animation. So why not setting the desired xlim after each plot, instead of holding it and deleting it?
It is not optimal, but it should not make much difference if you're grabbing frames for a movie.
If you are just "showing" a movie, it won't look very good, though. Maybe you can pause the loop for a tiny while after each xlim. I think you need also drawnow.
figure(1)
clf
for n=1:10
plot(1:10,(1:10)*n);
axis([1 10 1 100]);
drawnow;
pause(.2); %change this according to your needs
end
2 Comments
See Also
Categories
Find more on Animation in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!