如何将 matplotlib 3d 图更改为侧视图?

how to change matplotlib 3d plot to side-view?

如果有x、y、z坐标数组。我不是要显示静态二维图,可以通过

绘制
plot(x, y)

我是说

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot(x, y, z, label='parametric curve')

plt.show()

哪个matplotlib函数可以把视图改成侧视图?这样我就可以为 matplotlib GUI 添加按钮,当用户单击该按钮时,3d 图将绘制为 top-view/left-view/... 并且用户稍后仍可以使用鼠标以 3d 方式旋转图,就像我们在 CAD 软件中可以做的那样。

谢谢

这取决于您打算使用的 UI 工具包。 Matplotlib 可以使用多个后端,其中有文件后端、Qt4 后端、Qt5 后端、Wx 工具包后端等

如果您决定使用 Qt 后端在 python 中制作 UI,这里有一个示例如何使用 Qt 后端将 matplotlib 图嵌入 Qt canvas:https://matplotlib.org/gallery/user_interfaces/embedding_in_qt_sgskip.html

可以为 Wx 工具包完成类似的嵌入。我还猜想你可以使用像 http://mpld3.github.io/ 这样的 matplotlib JS 后端,然后继续在 Javascript

中制作 UI

如果我理解你的问题,你正在寻找函数 Axes3D.view_init

view_init(elev=None, azim=None)

Set the elevation and azimuth of the axes.

This can be used to rotate the axes programatically.

‘elev’ stores the elevation angle in the z plane. ‘azim’ stores the azimuth angle in the x,y plane.

if elev or azim are None (default), then the initial value is used which was specified in the Axes3D constructor.