Python 在绘图上不显示时间,但显示正确的日期
未在绘图上获取时间,但日期绘图正确,请检查列表dateIndex是否始终显示。 输出图如下所示:Python 在绘图上不显示时间,但显示正确的日期,python,matplotlib,Python,Matplotlib,未在绘图上获取时间,但日期绘图正确,请检查列表dateIndex是否始终显示。 输出图如下所示: def graphData(dateIndex,irValue,mar): dateIndex.pop() #take out the empty string irValue.pop() #equalising the size avgData = movingaverage(irValue,mar) spLen = len(dateIndex[mar-1:]
def graphData(dateIndex,irValue,mar):
dateIndex.pop() #take out the empty string
irValue.pop() #equalising the size
avgData = movingaverage(irValue,mar)
spLen = len(dateIndex[mar-1:])
fig = plt.figure()
ax1 = plt.subplot(1,1,1)
date = mdates.strpdate2num('%Y-%m-%d %H:%M:%S')
datenum = [date(i) for i in dateIndex] # date function here.
ax1.plot(datenum[-spLen:], avgData[-spLen:])
ax1.grid(True)
ax1.xaxis.set_major_locator(mticker.MaxNLocator(20))
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d \n %H:%M:%S'))
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)
plt.show()
你得到了很多次。滴答声是每5天午夜一次,这是您告诉它要做的。您好@tcaswell试图更改滴答声,但没有用,它仍然显示午夜时间,有没有办法更改它以获得正常的时间显示,提前感谢。感谢您的帮助@tcaswell,已经更改了显示格式,现在可以工作了,谢谢…如果你解决了你的问题,你能回答你自己的问题并在系统允许时接受答案吗?我很高兴你成功了我真的不明白你今天想干什么。