使用 Matplotlib 繪製 numpy datetime64


要在 Python 中使用 Matplotlib 繪製時間序列,可以按以下步驟進行 −

  • 使用 numpy 建立 x 和 y 點。

  • 使用 plot() 方法繪製已建立的 x 和 y 點。

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

示例

import matplotlib.pyplot as plt
import datetime
import numpy as np
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.array([datetime.datetime(2021, 1, 1, i, 0) for i in range(24)])
y = np.random.randint(100, size=x.shape)
plt.plot(x, y)
plt.show()

輸出

更新日期:2021-05-12

619 個瀏覽量

開啟你的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.