rotate a 3D plot and keep it the same size

I'm creating a GIF from a series of 3D plots, each one rotated from the previous by changing the viewpoint. Here is a snippet that does the frame generation:
for az=0:5:355
view([az,el]);
drawnow;
frame = getframe(gcf);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
imwrite(imind,cm,filename,'WriteMode','append','DelayTime',dt);
end
The problem I'm having is that each frame is magnified to fill the figure window, causing the plot to change size as it rotates. Here is a link to the GIF (it is also attached).
What view settings must I change to keep the 3D surface the same apparent size as I rotate it?

4 件のコメント

Krisztian Szucher
Krisztian Szucher 2017 年 9 月 25 日
編集済み: Krisztian Szucher 2017 年 9 月 25 日
With the gca command, you can get a handle for the current axes
k = gca
now you can use
inspect(k)
to see what settings are available. I'd suggest experimenting with the CameraViewAngle/Mode and PlotBoxAspect/Ratio properties from the inspector, to see if changing them result in the desired outcome.
Once you've figured out, you can use dot notation to set those parameters from code, e.g.
k.CameraViewAngleMode = 'manual'
Scott
Scott 2017 年 9 月 25 日
編集済み: Scott 2017 年 9 月 25 日
Yes, I've done that, but there are so many viewing parameters I don't know where to begin. I was hoping someone else had gone down this path and would know which ones I need to adjust. The "view" command bypasses having to deal with all the individual camera parameters. I was hoping there would be an easy way to prevent the automatic scaling of the plot to fill the figure window, instead of having to dive into all the nitty-gritty settings.
Michael Krumin
Michael Krumin 2017 年 11 月 18 日
Hi,
The relevant axis properties are: 'CameraTarget', 'CameraPosition', 'CameraViewAngle', and 'CameraViewAngleMode'.
If you change the 'viewing orientation' of the 3D plot using view(az, el), then the distance of the camera from your 3D object doesn't change, and you only need to set 'CameraViewAngle' to control the 'zoom'. After you set it once, then the 'CameraViewAngleMode' becomes 'manual', and the 'CameraViewAngle' doesn't change on every call to view(az, el), so no need to reset it for every frame.
Juan Diez Albar
Juan Diez Albar 2020 年 8 月 21 日
This piece of advice worked for me. Thank you soooooo much, Sir.

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

 採用された回答

Xiaofan Fei
Xiaofan Fei 2018 年 6 月 6 日

6 投票

axis vis3d

4 件のコメント

Ron Schmitt
Ron Schmitt 2019 年 7 月 25 日
Thank you!
This issue has irritated me for years!
Mango Wang
Mango Wang 2019 年 8 月 14 日
Cool!!!
Joseph
Joseph 2024 年 1 月 30 日
Did not work for me. I'm trying to fix the exact same issue as in the OP's gif but nothing seems to help. Very frustrating that this is the default behavior.
Joseph
Joseph 2024 年 1 月 30 日
Just figured it out after an hour of searching. Misunderstood what CameraViewAngle was and had it set to 0. After setting to 15 and manual it now works.

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

その他の回答 (1 件)

KSSV
KSSV 2017 年 9 月 25 日

0 投票

Read about axis, with this you can limit the axis. Also read about xlim, ylim and zlim with these you can set the limits of specific axes.

2 件のコメント

Scott
Scott 2017 年 9 月 25 日
編集済み: Scott 2017 年 9 月 25 日
I've tried setting XLim, YLim and ZLim. That doesn't solve the problem. Take a look at the example GIF I attached and you'll see the limits don't change as the figure is rotated. What does change is the magnification of the plot to fill the figure window. Thanks for the suggestion, though.
KSSV
KSSV 2017 年 9 月 25 日
Try converting your az and el to Cartesian using pol2cart and specify viewpoint by view([x y z]). With z as your desired value.

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

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

質問済み:

2017 年 9 月 23 日

コメント済み:

2024 年 1 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by