简体   繁体   中英

Access subplot axes returned by pandas.DataFrame.plot()

Is there a way I can access the axes returned by pandas.DataFrame.plot(subplots=True) ? I'd like to give each plot a title (and access other attributes), but my current attempts only affect the last subplot.

svv[['Flow2 L/s','GWT','DOC mg/L', 'Hgtot ng/L', 'MeHg ng/L']].dropna().plot(subplots=True, figsize=(20, 20)) 
plt.legend(loc='best')
ax[0].set_title('title1') # Doesn't alter any of the plots
ax[1].set_title('title2') # Doesn't alter any of the plots
plt.title('5 plots') # Title appears above the last plot

I have also tried using matplotlib.subplots() to create the subplots individually but this lead to the shared x-axis no longer only by at the intersection of all the Series being plotted.

"Returned" means it is the result of the call to plot . You can just store it in a variable:

ax = svv[['Flow2 L/s','GWT','DOC mg/L', 'Hgtot ng/L', 'MeHg ng/L']].dropna().plot(subplots=True, figsize=(20, 20))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM