在 Matplotlib 中绘制无轴无网格的三维散点图


要在 matplotlib 中绘制无轴的三维散点图,我们可以使用 scatter() 方法,并关闭轴。

步骤

  • 设置图表大小并调整子图之间的和周围的填充。
  • 使用 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()

Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.

输出

更新时间: 2021 年 6 月 1 日

739 次浏览

开启你的职业生涯

完成课程获得认证

入门
广告