python - How to use ax with Pandas and Matplotlib -
python - How to use ax with Pandas and Matplotlib -
i have basic question. using pandas dataframe create plot, want add together highlighting around dates.
in[122]: df1_99.plot(x='date', y='units', ylim=[0,11], figsize=[12,12])
out[122]:
i found code on stackoverflow add together highlighting.
fig, ax = plt.subplots() ax.plot_date(t, y, 'b-') ax.axvspan(*mdates.datestr2num(['10/27/2011', '11/2/2011']), color='red', alpha=0.5) fig.autofmt_xdate() plt.show()
my question how can utilize ax.avxspan current code? or need convert x='date', , y='units' numpy arrays , utilize format in code above?
pandas.dataframe.plot
homecoming matplotlib axessubplot
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()
if want create ax
object in advance, can pass plot
below
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()
finally, can current figure , axes objects using the next functions
fig = plt.gcf() ax = plt.gca()
python numpy pandas matplotlib
Comments
Post a Comment