0
我有15分鐘的時間間隔記錄數據。我想繪製這些數據,並讓x軸在每天顯示一個小刻度,並且每個月都會顯示一個重要的刻度。下面是我嘗試使用一月和二月繪製十五分鐘的間隔數據,以x軸爲單位記錄日期和月份
#!/usr/bin/env python3
import numpy as np
import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
#make some data
t = np.arange(0, 5664, 1) # Jan and Feb worth of 15 minute steps
s = np.sin(2*np.pi*t) # data measured
#plot the data
fig, ax = plt.subplots()
ax.plot(t, s)
#select formatting
days = mdates.DayLocator()
daysfmt = mdates.DateFormatter('%d')
months = mdates.MonthLocator()
monthsfmt = mdates.DateFormatter('\n%b')
的文件和其他Q & A的我已經閱讀並試圖在我的腦海拼湊做一個片段,我明白,我需要告訴matplotlib我想用於x軸的格式。這是我感到困惑的地方。我無法弄清楚如何指示繪圖數據是每15分鐘(每小刻度1440個樣本),所以當我顯示繪圖時,圖上沒有顯示任何內容。或者至少,我認爲這是因爲...
#apply formatting
ax.xaxis.set_major_locator(months)
ax.xaxis.set_major_formatter(monthsfmt)
ax.xaxis.set_minor_locator(days)
ax.xaxis.set_minor_formatter(daysfmt)
#select dates
datemin = dt.datetime.strptime('01/01/17', '%d/%m/%y')
datemax = dt.datetime.strptime('28/02/17', '%d/%m/%y')
ax.set_xlim(datemin, datemax)
plt.show()
疊加結果