필터 지우기
필터 지우기

How to prevent plots from resizing in making GIFs

조회 수: 12 (최근 30일)
Marco
Marco 2024년 5월 7일
댓글: DGM 2024년 5월 8일
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!

답변 (1개)

DGM
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
Marco
Marco 2024년 5월 7일
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 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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by