如何在 Matplotlib 中创建多色点?
matplotlibserver side programmingprogramming更新于 2025/4/30 15:22:17
要在 Matplotlib 中创建多色点,我们可以采取以下步骤−
- 初始化两个变量 x 和 y。
- 使用 scatter 方法,x 和 y 数据点均为绿色,标记大小为 2000。
- 使用 scatter 方法,x 和 y 数据点均为红色,标记大小为 1000。
- 使用 scatter 方法,x 和 y 数据点均为蓝色,标记大小为 500。
- 使用 scatter 方法,x 和 y 数据点均为白色,标记大小为 10。
- 要显示图形,请使用 show() 方法。
示例
from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x, y = 0, 0 plt.scatter(x, y, c='green', s=2000) plt.scatter(x, y, c='red', s=1000) plt.scatter(x, y, c='blue', s=500) plt.scatter(x, y, c='white', s=10) plt.show()
输出


