pandas.DataFrame.plot http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html将返回 matplotlibAxesSubplot
object.
ax = df1_99.plot(x='date', y='units', ylim=[0,11], figsize=[12,12])
ax.axvspan(*mdates.datestr2num(['10/27/2011', '11/2/2011']), color='red', alpha=0.5)
plt.show()
如果你想创建一个ax
提前对象,您可以将其传递到plot
如下
fig, ax = plt.subplots()
df1_99.plot(x='date', y='units', ylim=[0,11], figsize=[12,12], ax=ax)
ax.axvspan(*mdates.datestr2num(['10/27/2011', '11/2/2011']), color='red', alpha=0.5)
plt.show()
最后,您通常可以使用以下方式获取当前图形和轴对象以下功能 http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.gca
fig = plt.gcf()
ax = plt.gca()