在 Matplotlib 中繪出 Python 日期時間的累積圖


若要繪製 Python 日期時間的累積圖,我們可以採取以下步驟:

  • 設定影像大小並調整子圖周圍和其間的填充。

  • 製作一個包含一些大學資料的 Pandas 資料框,其中一個鍵用於時間差,另一個鍵用於次年入學的學生人數。

  • 使用 plot() 方法其中kind='bar'(按名稱分類)繪製資料框。

  • 使用 show() 方法顯示該影像。

示例

import pandas as pd
from matplotlib import pyplot as plt

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

college_student_data = {'durations': [1, 2, 2.5, 3, 4.5, 5, 5.5, 6, 6.5, 7], 'admissions': [5, 50, 150, 3380, 760, 340, 115, 80, 40, 10]}
df = pd.DataFrame(data=college_student_data)

df.plot(kind='bar', x='durations', y='admissions', legend=False, color='red', rot=0,)

plt.show()

輸出

更新於:2021 年 6 月 3 日

545 次瀏覽

開啟您的職業

透過完成課程獲取認證

開始吧
廣告