ValueError: DateFormatter found a value of x=0, which is an illegal date. This usually occurs becau

问题:

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()

解决办法:

首先,需要将时间格式转换为字符串str(h)
其次,需要将字符串转换为可以识别的时间格式datetime.datetime.strptime(str(h), '%Y-%m-%d %H:%M:%S')
最后,画图的时候横坐标的时间标签代码设置plt.gca().xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d %H:%M:%S'))

ValueError: DateFormatter found a value of x=0, which is an illegal date. This usually occurs becau_第1张图片

你可能感兴趣的:(python画图)