如何在 Matplotlib 中將散點大小轉換為資料座標?


若要將 Matplotlib 中的散點大小轉換為資料座標,我們可以執行以下步驟:

  • 設定圖形大小並調整子圖之間的和周圍的間距。
  • 使用 numpy 建立 **x** 和 **s** 資料點。
  • 建立圖形和一組子圖。
  • 使用 **X** 和 **s**、**cmap** 及顏色資訊製作散點圖。
  • 使用 **show()** 方法顯示圖形。

示例

import numpy as np
from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

X = np.array([[1, 1], [2, 1], [2.5, 1]])
s = np.array([20, 10000, 10000])

fig, ax = plt.subplots()

ax.scatter(X[:, 0], X[:, 1], s=s, cmap='plasma', c=s)

plt.show()

輸出

更新時間:2021 年 6 月 17 日

284 次瀏覽

開啟你的 職業生涯

完成課程可獲得認證

開始
廣告
© . All rights reserved.