时间不连续
Time is not continuous
因为下面的代码片段只在图表的开始和结束时产生时间,这意味着它将初始时间显示为 00:00,最终时间显示为 15:00(不显示中间值) 但时间不连续。我也想要中间时间,意思是 0:00 1:00 2:00 3:00 4:00 5:00 直到 15:00。如何让它成为连续的时间序列。
fig, ax = plt.subplots()
ax1=ax.twiny()
ax.plot(self.flttime1,smoothListGaussian(self.fLaZ1),'b-', label='Z axis (Left Smoothed)')
self.npfLaZ=(np.array(self.fLaZ1)+[0.6])
ax.plot(self.flttime1,(smoothListGaussian(self.npfLaZ)),'g-', label='Z axis (Left Smoothed)')
hfmt = mdates.DateFormatter('%M:%S')
ax1.xaxis.set_major_locator(mdates.SecondLocator())
ax1.xaxis.set_major_formatter(hfmt)
ax1.xaxis.set_minor_locator(mdates.SecondLocator())
ax1.set_xlim(dt.datetime(2000, 12, 5,0,0,0) ,dt.datetime(2007, 12, 5,0,15,0))
ax1.format_xdata = mdates.DateFormatter('%M:%S')
ax.grid(True)
plt.legend(loc=2)
fig.autofmt_xdate()
尝试导入 pandas
import pandas as pd
然后在行之后:
ax1.set_xlim(dt.datetime(2000, 12, 5,0,0,0) ,dt.datetime(2007, 12, 5,0,15,0))
添加:
ax1.set_xticks([pd.date_range(start=dt.datetime(2000, 12, 5,0,0,0), end=dt.datetime(2007, 12, 5,0,15,0), freq="1min")])
因为我没有你的数据集,请检查它是否有效。
因为下面的代码片段只在图表的开始和结束时产生时间,这意味着它将初始时间显示为 00:00,最终时间显示为 15:00(不显示中间值) 但时间不连续。我也想要中间时间,意思是 0:00 1:00 2:00 3:00 4:00 5:00 直到 15:00。如何让它成为连续的时间序列。
fig, ax = plt.subplots()
ax1=ax.twiny()
ax.plot(self.flttime1,smoothListGaussian(self.fLaZ1),'b-', label='Z axis (Left Smoothed)')
self.npfLaZ=(np.array(self.fLaZ1)+[0.6])
ax.plot(self.flttime1,(smoothListGaussian(self.npfLaZ)),'g-', label='Z axis (Left Smoothed)')
hfmt = mdates.DateFormatter('%M:%S')
ax1.xaxis.set_major_locator(mdates.SecondLocator())
ax1.xaxis.set_major_formatter(hfmt)
ax1.xaxis.set_minor_locator(mdates.SecondLocator())
ax1.set_xlim(dt.datetime(2000, 12, 5,0,0,0) ,dt.datetime(2007, 12, 5,0,15,0))
ax1.format_xdata = mdates.DateFormatter('%M:%S')
ax.grid(True)
plt.legend(loc=2)
fig.autofmt_xdate()
尝试导入 pandas
import pandas as pd
然后在行之后:
ax1.set_xlim(dt.datetime(2000, 12, 5,0,0,0) ,dt.datetime(2007, 12, 5,0,15,0))
添加:
ax1.set_xticks([pd.date_range(start=dt.datetime(2000, 12, 5,0,0,0), end=dt.datetime(2007, 12, 5,0,15,0), freq="1min")])
因为我没有你的数据集,请检查它是否有效。