Azzera filtri
Azzera filtri

How to prevent plots from resizing in making GIFs

12 visualizzazioni (ultimi 30 giorni)
Marco
Marco il 7 Mag 2024
Commentato: DGM il 8 Mag 2024
I am trying to implement two plots changing side-by-side as a GIF, but I'm noticing that the plots keep changing size and move around which makes the animation a bit jarring. Does anyone know what I could do to fix this?
Here is the code I'm using to generate the GIFs (the entire code is rather long so this is just the portion dedicated to plotting):
I initialize (outside the for loop) with
figure
subplot(1,2,1)
hold on
p1 = plot(dom_plot,u_sol, 'r');
xlim([-pi pi])
axis square
drawnow
subplot(1,2,2)
hold on
plot(k, norm(uv), 'b.', 'markersize', 10)
axis square
drawnow
And then within the for loop I update it as:
subplot(1,2,1)
p1 = plot(dom_plot, real(u_sol), 'r');
cla(p1)
axis([-pi, pi, -max_plot, max_plot])
drawnow
axis square
subplot(1,2,2)
plot(uv_0(end), norm(uv_0(1:end-1)), 'b.', 'markersize', 10)
drawnow
axis square
exportgraphics(gcf,'w_4_2_animation.gif','Append',true);
Below is an example of what one of these animations looks like. Any help would be much appreciated; thank you!

Risposte (1)

DGM
DGM il 7 Mag 2024
Modificato: DGM il 7 Mag 2024
Figure out the appropriate range of x and y limits you need, and then explicitly set them using xlim() and ylim().
  2 Commenti
Marco
Marco il 7 Mag 2024
Hello, yes I am aware of xlim() and ylim() (I used axis() for the plot on the left which combines these) but for the plot on the right, I want to keep it so that the x and y limits keep updating every iteration. I just want the physical size of the plots to remain the same, if this is possible.
DGM
DGM il 8 Mag 2024
If you want to allow the limits (and tick labels) to change in the loop, you'll have to make room for them in order to keep the plot boxes fixed in one place. Use your loop and inspect the 'position' property of the axes in order to find something that will allow room for the tick labels in all cases. Then explicitly set that in the loop so that it stays fixed.

Accedi per commentare.

Categorie

Scopri di più su Animation in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by