在 Matplotlib 中散佈一個 2D numpy 陣列


要在 matplotlib 中散佈一個 2D numpy 陣列,我們可以採取以下步驟 −

步驟

  • 設定圖形大小並調整子圖之間和周圍的內邊距。

  • 建立 100×3 維度的隨機資料。

  • 使用 scatter() 方法來繪製 2D numpy 陣列,即資料。

  • 要顯示圖形,請使用show() 方法。

示例

import numpy as np
from matplotlib import pyplot as plt

# Set the figure size
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

# Random data of 100×3 dimension
data = np.array(np.random.random((100, 3)))

# Scatter plot
plt.scatter(data[:, 0], data[:, 1], c=data[:, 2], cmap='hot')

# Display the plot
plt.show()

輸出

它將產生以下輸出 −

更新於:2022-02-02

21K+ 閱讀量

開啟您的 職業生涯

完成課程後獲得認證

開始學習
廣告
© . All rights reserved.