访问pandas.DataFrame.plot()返回的子图轴

时间:2015-03-14 23:00:45

标签: python python-2.7 pandas matplotlib

有没有办法可以访问pandas.DataFrame.plot(subplots=True)返回的轴?我想给每个情节一个标题(并访问其他属性),但我目前的尝试只影响最后一个子情节。

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

我还尝试使用matplotlib.subplots()单独创建子图,但这导致共享的x轴不再仅仅是在绘制的所有Series的交叉点。

1 个答案:

答案 0 :(得分:2)

"返回的"意味着它是调用plot的结果。您可以将其存储在变量中:

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