在 Matplotlib 中绘制没有轴的 3D 条形图
matplotlibpythondata visualization更新于 2025/6/1 12:28:17
要绘制没有轴的 3D 条形图,我们可以采取以下步骤
- 设置图形大小并调整子图之间和周围的填充。
- 使用 figure() 方法创建新图形或激活现有图形。
- 将轴添加到当前图形作为子图排列。
- 使用 numpy 创建 x3、y3 和 z3 数据点。
- 使用 numpy 创建 dx、dy 和 dz 数据点。
- 使用 bar3d() 方法绘制 3D 条形图。
- 要隐藏轴,请使用名称为 axis('off') 的类。
- 要显示图形,请使用show() 方法。
示例
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
x3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
y3 = [5, 6, 7, 8, 2, 5, 6, 3, 7, 2]
z3 = np.zeros(10)
dx = np.ones(10)
dy = np.ones(10)
dz = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
ax1.bar3d(y3, x3, z3, dx, dy, dz, color="red")
ax1.axis('off')
plt.show()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

