python - Python 3D sublplots 具有多个 İimages 和一个颜色条
问题描述
我有一些数据,当我尝试使用 subplot 将它们并排绘制时,我遇到了麻烦。这是我的代码
fig = plt.figure()
ax = fig.add_subplot(212, projection='3d')
surf = ax.plot_trisurf(X, Y, Z, cmap=cm.inferno,
linewidth=0, shade=True, antialiased=True)
ax.set_zlim3d(None,76)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
ax = fig.add_subplot(221, projection='3d')
surf = ax.plot_trisurf(X, Y, Z, cmap=cm.inferno,
linewidth=0, shade=True, antialiased=True)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
ax = fig.add_subplot(222, projection='3d')
surf = ax.plot_trisurf(X, Y, Z, cmap=cm.inferno,
linewidth=0, shade=True, antialiased=True)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
plt.colorbar(surf)
plt.show()
解决方案
import matplotlib
import matplotlib.pyplot as plt
# create mockup data
X, Y = [], []
for x in range(10):
for y in range(10):
X.append(x)
Y.append(y)
Z = [1] * len(X)
# color settings
cmap = matplotlib.cm.inferno
norm = matplotlib.colors.Normalize(vmin=5, vmax=10)
colorbar = matplotlib.cm.ScalarMappable(norm=norm, cmap=cmap)
# allocate subplots
fig = plt.figure()
for cell in [231, 233, 235]:
ax = fig.add_subplot(cell, projection='3d')
surf = ax.plot_trisurf(X, Y, Z, cmap=cmap)
# create colorbar
fig.subplots_adjust(right=0.7)
cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
fig.colorbar(colorbar, cax=cbar_ax)
plt.show()
推荐阅读
- powershell - PowerShell - 使用 REST API 下载包含错误内容的 TXT 文件
- flutter - 在 Flutter/Dart 中从 Stream 中过滤数据
- c++ - 了解模板外部函数签名中“typename”的使用
- excel - range.formula 问题
- python - 如何在python中比较两个数据
- python - 如何使用python从github正确下载json文件
- c# - 我正在尝试让我的 2D 统一角色跳跃
- c - 释放后的堆使用源自内存泄漏
- javascript - 如何使用 javaScript 从其他下拉菜单中选择一个下拉项目?
- reactjs - express 和 Mongo DB - 高级分页