Python 显示日期为一年中月份的时间序列

Python 显示日期为一年中月份的时间序列,python,matplotlib,time-series,Python,Matplotlib,Time Series,我有数据集,我想可视化时间序列。但是,日期轴将日期显示为时间戳。我希望它能像一年中的一个月(一月到十二月)那样显示出来。如何在timeseries中格式化日期? 有一项功能可以自动为您优化x轴。使用了matplotlib.dates.AutoDateLocator。你的品质符合你的意图吗 fig = plt.figure(figsize=(16,9),dpi=144) ax = fig.add_subplot(111) plt.plot(df.index, df['data'], linest

我有数据集,我想可视化时间序列。但是,日期轴将日期显示为时间戳。我希望它能像一年中的一个月(一月到十二月)那样显示出来。如何在timeseries中格式化日期?

有一项功能可以自动为您优化x轴。使用了
matplotlib.dates.AutoDateLocator
。你的品质符合你的意图吗

fig = plt.figure(figsize=(16,9),dpi=144)
ax = fig.add_subplot(111)

plt.plot(df.index, df['data'], linestyle='dashed')

locator = mdates.AutoDateLocator()
formatter = mdates.ConciseDateFormatter(locator)

ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)

plt.show()

你好欢迎来到SO。请参考添加的图片,谢谢