2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > python三维图视角旋转_在python-matplotlib-Jupyter Noteb中交互式旋转三维绘图

python三维图视角旋转_在python-matplotlib-Jupyter Noteb中交互式旋转三维绘图

时间:2021-12-31 10:31:50

相关推荐

python三维图视角旋转_在python-matplotlib-Jupyter Noteb中交互式旋转三维绘图

我想知道怎样才能像this视频中描述的那样交互地旋转一个3D图(如果你决定从上面或下面,或者从右边或左边)。我可以在spyder或jupyter笔记本中生成一个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()

非常感谢你提前!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。