使用 Matplotlib 中的繪圖方法繪製散點


要在 Matplotlib 中使用 plot 方法繪製散點,我們可以採取以下步驟:

  • 使用 NumPy 建立隨機資料點 (x1 和 x2)。
  • 使用標記大小為 20 和綠色繪製 x1 資料點,方法是使用 plot() 方法。
  • 使用標記大小為 10 和紅色繪製 x2 資料點,方法是使用 plot() 方法。

示例

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()

輸出

更新日期:2021-05-06

536 次檢視

開啟你的 職業生涯

完成學習後取得認證

開始
廣告
© . All rights reserved.