當我有 365 個資料點時,我可以使用以下代碼創建一個帶有月份名稱的圖:
y = np.random.normal(size=365)
x = np.array(range(len(y)))
plt.plot(x, y)
plt.xlabel('Month')
locator = mdates.MonthLocator()
fmt = mdates.DateFormatter('%b')
X = plt.gca().xaxis
X.set_major_locator(locator)
X.set_major_formatter(fmt)
這是結果,這正是我正在尋找的:

我想做同樣的事情,但只有 12 個資料點(每個月一個)。如果我只是將 365 更改為 12 ( y = np.random.normal(size=12)),它看起來像這樣:

我怎樣才能讓它像第一張圖一樣在 x 軸上顯示所有月份?
我嘗試將引數傳遞給
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/317778.html
標籤:Python matplotlib
