axis changes even after "axis equal"

21 visualizaciones (últimos 30 días)
Luca Amerio
Luca Amerio el 13 de Abr. de 2015
Comentada: pfb el 14 de Abr. de 2015
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

Respuesta aceptada

Chad Greene
Chad Greene el 13 de Abr. de 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)
  1 comentario
Luca Amerio
Luca Amerio el 14 de Abr. de 2015
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.

Iniciar sesión para comentar.

Más respuestas (1)

pfb
pfb el 14 de Abr. de 2015
Editada: pfb el 14 de Abr. de 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 comentarios
Luca Amerio
Luca Amerio el 14 de Abr. de 2015
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 el 14 de Abr. de 2015
You're welcome. But I think you accepted the other answer :)

Iniciar sesión para comentar.

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by