我想知道如何以this视频中描述的方式交互式旋转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()

非常感谢你!

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐