【发布时间】:2021-10-12 08:26:42
【问题描述】:
我正在阅读以下文章 3D animation using matplotlib。它以 3D 形式显示动画。
我正在考虑以下场景:
- 我有一个 x-y 网格,[1,2,...,20] X [1,2,...,20]
- 为每个点分配一个 z 值。
- 基于 1. 和 2.,我绘制了 3-D 梯度图,如下所示
假设我有 5 个 20X20 的 z 值数据 (.xlsx)。因此,我得到了上面 5 个不同的图表。
现在,我想在一个图表中绘制所有 5 个图表,但使用 滑块 这样当我将滑块从 1 移动到 5 时,我可以获得图表的动画(变化),但是在同一个网格中。
这里只提供一张图(一个数据)的代码
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
rm = pd.read_excel("test_3d.xlsx", header = None)
rec = np.shape(rm)
X = np.arange(1,rec[1]+1,1)
Y = np.arange(1,rec[0]+1,1)
x , y = np.meshgrid(X,Y)
# Plot the surface.
surf = ax.plot_surface(x, y, rm, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
# Customize the z axis.
ax.set_zlim(-110, -80)
ax.zaxis.set_major_locator(LinearLocator(10))
# A StrMethodFormatter is used automatically
ax.zaxis.set_major_formatter('{x:.02f}')
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
如何修改代码以获得我想要的?请给个提示。谢谢!
【问题讨论】:
标签: python matplotlib animation plot 3d