问题出现在注释行(两行)中。
import matplotlib.pyplot as plt
import datetime
import matplotlib.dates as mdates
import numpy as np
fix, ax = plt.subplots()
months = mdates.MonthLocator()
dateFmt = mdates.DateFormatter('%m/%d/%y')
ax.xaxis.set_major_formatter(dateFmt)
ax.xaxis.set_minor_locator(months)
ax.tick_params(axis='both', direction='out', labelsize=15) # 上面和右边坐标轴刻度没出现?
date1 = datetime.date(2008, 4, 17)
date2 = datetime.date(2017, 5, 4)
delta = datetime.timedelta(days=5)
dates = mdates.drange(date1, date2, delta)
y = np.random.normal(100, 15, len(dates))
ax.plot_date(dates, y, 'b-', alpha=0.7)
# plt.tight_layout()
fig.autofmt_xdate() # x 坐标的lable没有自动旋转?
plt.show()