Jupyter |如何旋转3D图形

时间:2017-11-15 15:45:12

标签: python matplotlib jupyter-notebook

我不确定如何在Python Jupyter笔记本中旋转图形,它对我来说是静态的而不是在鼠标移动时旋转

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()

enter image description here

2 个答案:

答案 0 :(得分:26)

要启用交互性,您需要使用matplotlib的@Component({ selector: 'body', template: `<child></child>` }) export class AppComponent { @HostBinding('class') public cssClass = 'class1'; } 后端。您可以通过运行notebook

来执行此操作

这必须在你绘制任何东西之前完成,例如:

%matplotlib notebook

答案 1 :(得分:-1)

如matplotlib网站所述,您可以通过导入mplot3d来创建交互式图表。请使用以下示例Rotate Axes

我将包含代码,以防将来链接不可用。

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)