我想使用下面的數據集按小時(0-23)獲取聯機活動。在python 3.x版本中使用matplotlib時什麼都不顯示
樣本數據集名爲activities
。該數據集是這樣的:
hour activity_counts
00 2
01 30
02 25
03 40
04 10
05 4
06 8
07 10
08 30
09 50
10 100
11 300
12 600
13 340
...
23 780
這裏是我的代碼:
plt.plot(x=activities['hour'], y=activities['activity_counts'],fmt="H")
plt.title("Customer Online Activities by Hour")
plt.xlabel("Hours")
plt.ylabel("Hour Activity")
plt.grid(True)
plt.show()
這樣的情節。情節上什麼也沒有。
那麼,什麼是錯我的代碼?
是的。當我刪除'''x ='''和''''''''時,它工作。而且,我只是刪除'''fmt ='H''''如果我不' t刪除,格式問題出現錯誤。 – Rya
@Rya感謝您的反饋。我也從答案中刪除了'fmt'。請注意,您仍然可以使用''H「'標記,只需將其傳遞給函數而不需要'fmt ='(同樣的問題)。 – MSeifert