我有一個每日溫度隨時間變化的資料框
time temp temp_mean
00:01:51.57 185.94 185.94
00:01:52.54 187.48 186.71
00:01:53.51 197.85 190.4233333
00:01:54.49 195.71 191.745
00:01:55.46 197.22 192.84
00:01:56.43 187.33 191.9216667
00:01:57.41 194.18 192.2442857
00:01:58.38 199.9 193.20125
00:01:59.35 184.23 192.2044444
00:02:00.33 201.34 193.118
00:02:01.30 200.12 193.7545455
00:02:02.27 199.13 194.2025
00:02:03.24 187.47 193.6846154
00:02:04.22 187.65 193.2535714
00:02:05.19 195.59 193.4093333
00:02:06.17 188.7 193.115
00:02:07.14 196.16 193.2941176
00:02:08.11 191.17 193.1761111
00:02:09.08 198.62 193.4626316
00:02:10.06 190.79 193.329
00:02:11.03 193.35 193.33
00:02:12.00 199.36 193.6040909
00:02:12.98 190.76 193.4804348
00:02:13.95 205.16 193.9670833
00:02:14.92 194.89 194.004
00:02:15.90 185.3 193.6692308
像這樣。(12000 行)我想將時間與溫度繪制為線圖,在 x 軸上每小時標記一次(1 小時間隔)。但不知何故,我無法以適當的頻率分配 x 滴答聲。
fig, ax = plt.subplots()
ax.plot(data['time'], data['temp'])
ax.plot(data['time'], data['temp_mean'],color='red')
xformatter = mdates.DateFormatter('%H:%M')
xlocator = mdates.HourLocator(interval = 1)
## Set xtick labels to appear every 15 minutes
ax.xaxis.set_major_locator(xlocator)
## Format xtick labels as HH:MM
ax.xaxis.set_major_formatter(xformatter)
fig.autofmt_xdate()
ax.tick_params(axis='x', rotation=45)
plt.show()

這里xticks似乎是擁擠和重疊的,但我需要從蜱0:00到23:00一個小時的時間間隔。我該怎么辦 ?
uj5u.com熱心網友回復:
- 的轉換
'time'列到datetime dtype與
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/345398.html標籤:Python 熊猫 约会时间 matplotlib xticks
