在绘制以时间戳为索引的pandas系列时,如何在matplotlib中格式化x轴?

时间:2018-04-26 19:46:36

标签: python matplotlib timestamp format axis-labels

我有一个带有两列的pandas系列,Index(时间戳)和浮点数

screenshot of  Series

我尝试使用Matplotlib绘图如下

s2.plot()

给出了以下情节

enter image description here

现在我想格式化x轴,只显示'%Y-%m-%d'格式的时间戳 所以我试试

fig, ax = plt.subplots()
xdfmt = dates.DateFormatter('%Y-%m-%d')
ax.xaxis.set_major_formatter(xdfmt)
ax.xaxis_date()
s2.plot()

失败如下

  

dt = datetime.datetime.fromordinal(ix).replace(tzinfo = UTC)

     

ValueError:序数必须为> = 1

如何格式化x轴以显示清晰的x轴标签?

0 个答案:

没有答案