在 Matplotlib 中绘制没有轴和网格的 3d 图上的散点

matplotlibpythondata visualization更新于 2025/6/1 2:52:17

要在 matplotlib 中绘制没有轴的 3D 图上的散点,我们可以使用 scatter() 方法并将轴设置为 OFF。

步骤

  • 设置图形大小并调整子图之间和周围的填充。
  • 使用 figure() 方法创建新图形或激活现有图形。
  • 添加轴作为子图排列。
  • 使用 numpy 创建 xs、ys 和 zs 数据点。
  • 使用 scatter() 方法创建散点图。
  • 使用 ax.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()
ax = fig.add_subplot(projection="3d")
xs = np.random.rand(100)
ys = np.random.rand(100)
zs = np.random.rand(100)
ax.scatter(xs, ys, zs, c=xs, cmap="copper")
ax.axis('off')
plt.show()

输出


相关文章


有用资源