X轴刻度在图中未显示

时间:2020-10-12 02:51:57

标签: python matplotlib

尝试使用matplotlib绘制全年的日期。但是我的x轴日期未在图中显示。试图打印基于月的x轴刻度,即使这样也不起作用。下面是尝试的代码,请指出我想念的地方?

from matplotlib.dates import DateFormatter,DayLocator, MonthLocator

#Plot the daily granularity for the year
ax = plt.subplot(111)

#Get ticks for major and minor days
alldays = DayLocator()
mloc = MonthLocator()

month_fmt = DateFormatter('%m')
ax.xaxis_date()
ax.xaxis.set_major_locator(mloc)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_formatter(month_fmt)
ax.format_xdata = DateFormatter('% m')


plt.plot_date(plot_date_freq["Date"],plot_date_freq["DateValue"],fmt="-")
plt.grid(True)

plt.xticks(rotation=45)

#set the label and title for the chart
plt.title("Review for the year 2015")
plt.xlabel("Date")
plt.ylabel("No. of reviews")
plt.gcf().autofmt_xdate()
plt.show()

enter image description here

0 个答案:

没有答案
相关问题