如何在 Matplotlib 中製作多色點?


要在 matplotlib 中製作多色點,我們可以按照以下步驟進行:

  • 初始化兩個變數,x 和 y。
  • 使用具有綠色且標記器大小為 2000 的 x 和 y 資料點的 scatter 方法。
  • 使用具有紅色且標記器大小為 1000 的 x 和 y 資料點的 scatter 方法。
  • 使用具有藍色且標記器大小為 500 的 x 和 y 資料點的 scatter 方法。
  • 使用具有白色且標記器大小為 10 的 x 和 y 資料點的 scatter 方法。
  • 要顯示圖形,請使用 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()

輸出

更新於: 06-05-2021

242 次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.