在 Matplotlib 中用三叶草符号绘制散点
matplotlibpythondata visualization更新于 2025/7/6 4:28:17
要在 Matplotlib 中用三叶草符号绘制散点,我们可以采取以下步骤 −
- 设置图形大小并调整子图之间和周围的填充。
- 使用 numpy 创建 x、y 和 z 数据点。
- 使用 scatter() 方法绘制 x、y 和 s。
- 设置 X 和 Y 轴标签。
- 在图的左上角放置图例。
- 要显示图形,请使用 show() 方法。
示例
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.arange(0.0, 50.0, 2.0)
y = x ** 1.3 + np.random.rand(*x.shape) * 30.0
s = np.random.rand(*x.shape) * 800 + 500
plt.scatter(x, y, s, c=x, alpha=0.5, marker=r'$\clubsuit$',
label="Legend", cmap="plasma")
plt.xlabel("X-Axis")
plt.ylabel("Y-Axis")
plt.legend(loc='upper left')
plt.show()
输出

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

