如何设置“相机位置"对于使用 python/matplotlib 的 3d 图? [英] how to set "camera position" for 3d plots using python/matplotlib?

查看:28
本文介绍了如何设置“相机位置"对于使用 python/matplotlib 的 3d 图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何使用 mplot3d 生成漂亮的 3d 数据图,到目前为止我很高兴.我现在想做的是一个旋转表面的小动画.为此,我需要为 3D 投影设置相机位置.我想这一定是可能的,因为在交互使用 matplotlib 时可以使用鼠标旋转表面.但是我怎么能从脚本中做到这一点呢?我在 mpl_toolkits.mplot3d.proj3d 中发现了很多转换,但我不知道如何将这些用于我的目的,我也没有找到任何我想要做的例子.

I'm learning how to use mplot3d to produce nice plots of 3d data and I'm pretty happy so far. What I am trying to do at the moment is a little animation of a rotating surface. For that purpose, I need to set a camera position for the 3D projection. I guess this must be possible since a surface can be rotated using the mouse when using matplotlib interactively. But how can I do this from a script? I found a lot of transforms in mpl_toolkits.mplot3d.proj3d but I could not find out how to use these for my purpose and I didn't find any example for what I'm trying to do.

推荐答案

通过相机位置",听起来您想要调整用于查看 3D 绘图的仰角和方位角.您可以使用 ax.view_init.我使用下面的脚本首先创建了绘图,然后我确定了一个好的高程或 elev,从中可以查看我的绘图.然后我调整了方位角或 azim,以在我的绘图周围改变完整的 360 度,在每个实例中保存图形(并在我保存绘图时注意哪个方位角).对于更复杂的相机平移,您可以同时调整仰角和角度以达到所需的效果.

By "camera position," it sounds like you want to adjust the elevation and the azimuth angle that you use to view the 3D plot. You can set this with ax.view_init. I've used the below script to first create the plot, then I determined a good elevation, or elev, from which to view my plot. I then adjusted the azimuth angle, or azim, to vary the full 360deg around my plot, saving the figure at each instance (and noting which azimuth angle as I saved the plot). For a more complicated camera pan, you can adjust both the elevation and angle to achieve the desired effect.

    from mpl_toolkits.mplot3d import Axes3D
    ax = Axes3D(fig)
    ax.scatter(xx,yy,zz, marker='o', s=20, c="goldenrod", alpha=0.6)
    for ii in xrange(0,360,1):
        ax.view_init(elev=10., azim=ii)
        savefig("movie%d.png" % ii)

这篇关于如何设置“相机位置"对于使用 python/matplotlib 的 3d 图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆