我有几秒钟的时间列表。例如:
[0, 15, 30, .... 18615, 18630, 18645]
我希望将它绘制为小时:分钟:秒对着同样长的值列表。
我尝试过使用日期格式化程序但是出现以下错误:
ValueError: DateFormatter found a value of x=0, which is an illegal date. This usually occurs because you have not informed the axis that it is plotting dates, e.g., with ax.xaxis_date()
我已经实现了ax.xaxis_date()
,所以不应该是问题。希望你能帮助我让x轴以小时而不是秒来显示时间。
相关代码:
self.samp_freq = 15
self.noise_samp = np.arange(0, self.time_total, self.samp_freq)
self.random_noise = np.random.normal(0, 10, len(self.noise_samp))
self.noi_ax.xaxis.set_major_locator(mticker.MaxNLocator(5))
self.noi_ax.xaxis_date()
self.noi_ax.xaxis.set_major_formatter(mdates.DateFormatter('%H:%M:%S'))
self.noi_ax.plot(self.noise_samp, self.scaled_random_noise)[0]
self.noi_ax.set_xlabel('time (sec)')
self.noi_ax.set_ylabel('noise (uGal')