Python 每6个月显示x轴日期
如何使图表上的日期每6个月而不是每个月显示在x轴上?您可以在初始化Python 每6个月显示x轴日期,python,date,matplotlib,Python,Date,Matplotlib,如何使图表上的日期每6个月而不是每个月显示在x轴上?您可以在初始化月定位器时指定要勾选的月份。所以在一月和七月 fig_2 = plt.figure(figsize=(16,6)) axes2 = fig_2.add_axes([0,0,1,1]) axes2.plot(tesla_df['Volume']) axes2.plot(gm_df['Volume']) axes2.plot(ford_df['Volume']) plt.legend(['Tesla','GM','Ford'])
月定位器时指定要勾选的月份。所以在一月和七月
fig_2 = plt.figure(figsize=(16,6))
axes2 = fig_2.add_axes([0,0,1,1])
axes2.plot(tesla_df['Volume'])
axes2.plot(gm_df['Volume'])
axes2.plot(ford_df['Volume'])
plt.legend(['Tesla','GM','Ford'])
axes2.xaxis.set_minor_locator(dates.MonthLocator())
axes2.xaxis.set_minor_formatter(dates.DateFormatter('%m--%Y'))
如果您不关心勾选哪个月,还可以指定间隔
matplotlib.dates.MonthLocator((1,7))
您可以在初始化MonthLocator
时指定要勾选的月份。所以在一月和七月
fig_2 = plt.figure(figsize=(16,6))
axes2 = fig_2.add_axes([0,0,1,1])
axes2.plot(tesla_df['Volume'])
axes2.plot(gm_df['Volume'])
axes2.plot(ford_df['Volume'])
plt.legend(['Tesla','GM','Ford'])
axes2.xaxis.set_minor_locator(dates.MonthLocator())
axes2.xaxis.set_minor_formatter(dates.DateFormatter('%m--%Y'))
如果您不关心勾选哪个月,还可以指定间隔
matplotlib.dates.MonthLocator((1,7))