我想知道如何像本视频所述交互式地旋转3D图(如果您从上方或下方或从右或左进行选择)。我可以在spyder或jupyter Notebook中生成3D图,但此后它保持静态,无法与之交互并旋转/更改视点角度。
这是代码:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
scale = 8
# Make data.
X = np.arange(-scale, scale, 0.25)
Y = np.arange(-scale, scale, 0.25)
X, Y = np.meshgrid(X, Y)
Z = X**2 + Y**2
# Plot the surface.
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
# Customize the z axis.
ax.set_zlim(0, 100)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# rotate the axes and update
for angle in range(0, 360):
ax.view_init(30, 40)
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
提前非常感谢您!
好吧,我在另一篇文章中找到了答案:
如何在IPython Notebook中打开交互式Matplotlib窗口?。
%matplotlib qt
必须在脚本的开头编写以下行+您必须重新启动jupyter笔记本,它才能正常工作
非常感谢您的帮助!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句