axis changes even after "axis equal"
22 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Chad Greene
2015 年 4 月 13 日
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)
その他の回答 (1 件)
pfb
2015 年 4 月 14 日
編集済み: pfb
2015 年 4 月 14 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Animation についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!