使用 Matplotlib 中的 plot 方法绘制散点图
matplotlibserver side programmingprogramming更新于 2025/8/26 8:37:17
要使用 Matplotlib 中的 plot 方法绘制散点图,我们可以采取以下步骤−
- 使用 numpy 创建随机数据点 (x1 和 x2)。
- 使用 plot() 方法绘制 x1 数据点,标记大小为 20,颜色为绿色。
- 使用 plot() 方法绘制 x2 数据点,标记大小为 10,颜色为红色。
示例
import numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True x1 = np.random.randn(20) x2 = np.random.randn(20) plt.plot(x1, 'go', markersize=20) plt.plot(x2, 'ro', ms=10) plt.show()
输出


