How to prevent plots from resizing in making GIFs
8 次查看(过去 30 天)
显示 更早的评论
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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1689092/image.gif)
0 个评论
回答(1 个)
DGM
2024-5-7
编辑:DGM
2024-5-7
Figure out the appropriate range of x and y limits you need, and then explicitly set them using xlim() and ylim().
2 个评论
DGM
2024-5-8
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!