使用 Matplotlib 根據時間繪製事件的方法是什麼?


要使用 Matplotlib 根據時間繪製事件,我們可以採用以下步驟:

  • 設定圖形尺寸,調整子圖之間和周圍的空白。
  • 製作可能發生事件的資料點列表。
  • 繪製一條水平線,帶有 y,xmin 和 xmax。
  • 繪製位於給定位置的相同的平行線。
  • 要顯示圖形,請使用 show() 方法。

示例

import matplotlib.pyplot as plt

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

a = [1, 2, 5, 6, 9, 11, 15, 17, 18]

plt.hlines(1, 0, 24)

plt.eventplot(a, orientation='horizontal', colors='b')

plt.show()

輸出

更新於: 2021-06-18

844 次檢視

職業起步

完成課程獲得認證

開始
廣告