Python 木星| 如何旋转 3D 图形
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47311632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jupyter | How to rotate 3D graph
提问by Vineet
I am not sure about how to rotate graph in Python Jupyter notebook, its static for me and not rotate on mouse movement
我不确定如何在 Python Jupyter notebook 中旋转图形,它对我来说是静态的,而不是在鼠标移动时旋转
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x =[1,2,3,4,5,6,7,8,9,10]
y =[5,6,2,3,13,4,1,2,4,8]
z =[2,3,3,3,5,7,9,11,9,10]
ax.scatter(x, y, z, c='r', marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
回答by Hannes Ovrén
To enable interactivity you need to use the notebook
backend of matplotlib. You can do this by running %matplotlib notebook
.
要启用交互性,您需要使用notebook
matplotlib的后端。你可以通过运行来做到这一点%matplotlib notebook
。
This must be done before you plot anything, e.g.:
这必须在绘制任何内容之前完成,例如:
%matplotlib notebook
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import axes3d
fig = ...
回答by alexchet
As described on matplotlib website you can create an interactive graph by importing mplot3d
. Please use the following sample Rotate Axes.
如 matplotlib 网站所述,您可以通过导入mplot3d
. 请使用以下示例旋转轴。
I am going to include the code just in case the link is not available in future.
我将包含代码,以防将来链接不可用。
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
%matplotlib notebook
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# load some test data for demonstration and plot a wireframe
X, Y, Z = axes3d.get_test_data(0.1)
ax.plot_wireframe(X, Y, Z, rstride=5, cstride=5)
# rotate the axes and update
for angle in range(0, 360):
ax.view_init(30, angle)
plt.draw()
plt.pause(.001)