如何使用 Matplotlib 在 Python 中繪製陣列?


若要繪製 Python 中的 陣列,我們可以採取以下步驟:

  • 設定圖形大小並調整子圖之間和周圍的邊距。
  • 使用 numpy 建立兩個陣列 xy
  • 使用 title() 方法設定曲線的標題。
  • 繪製 xy 資料點,使用紅色。
  • 要顯示圖形,請使用 show() 方法。

示例

import numpy as np
import matplotlib.pyplot as plt

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

x = np.array([5, 4, 1, 4, 5])
y = np.sort(x)

plt.title("Line graph")
plt.plot(x, y, color="red")

plt.show()

輸出

更新於: 2023 年 8 月 25 日

54K+ 瀏覽次數

開啟你的職業生涯

完成課程,獲得認證

開始
廣告
© . All rights reserved.