axis changes even after "axis equal"

28 ビュー (過去 30 日間)
Luca Amerio
Luca Amerio 2015 年 4 月 13 日
コメント済み: pfb 2015 年 4 月 14 日
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

採用された回答

Chad Greene
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 件のコメント
Luca Amerio
Luca Amerio 2015 年 4 月 14 日
Yes, I already though to both these solutions. Was hoping for a simpler one because I need to teach this to students that are not familiar with MATLAB.
Using delete, set of h.XData=[...] are adding a further complication to a simple problem.
To bad: I was hoping the solution to be cleaner.

サインインしてコメントする。

その他の回答 (1 件)

pfb
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 件のコメント
Luca Amerio
Luca Amerio 2015 年 4 月 14 日
Thank you very much. This could be a doable workaround. I will decide if either this or delete(h) cause less questions.
Thank you very much.
pfb
pfb 2015 年 4 月 14 日
You're welcome. But I think you accepted the other answer :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by