这里是一个示例代码,我想在x轴上绘制整个日期
import datetime
import matplotlib.pyplot as plt
import random
import numpy as np
from matplotlib.dates import DateFormatter
years = np.arange( 2005, 2016, 1)
years[1] = 2005
years[2] = 2005
months = [ 3, 2, 1, 5, 7, 12, 2, 3, 5, 2, 6]
dates = []
for Y in years:
dates = dates + [ datetime.datetime(Y, 6 , 4) ]
y = np.random.randn(len(dates))
fig, ax = plt.subplots()
ax.plot_date(dates, y, 'r+', ms = 2, mew = 12)
ax.fmt_xdata = DateFormatter('%y-%m-%d')
fig.autofmt_xdate()
plt.show()
我需要的是在x轴上写下所有日期,如图所示
您建议我更改我的代码?