将子图的pandas plot保存到一个文件中

时间:2017-12-13 13:17:33

标签: python pandas matplotlib plot

我正在使用以下数据框在pandas / jupyter笔记本中创建子图

METHOD1       A           B             C              D             E
METHOD2                                                                
high       1410          14           426          13781             1
low       74142         303        757024          95105            37
medium    99174         670        277013         640000           127
mono      46599         207        405108          16793           160

axs = ct.plot(kind='barh', subplots=True, legend=False, figsize=(24,16))
for ax in axs:
    ax.set_xscale('log')

在Jupyter中,我得到一张包含4个子图的图像。我想将那个情节保存到一个png, 但是

fig=axs.get_figure()
fig.savefig('plot.png')

给出错误消息

  

AttributeError:' numpy.ndarray'对象没有属性' get_figure'

因为axs是子图的数组 我可以保存各个子图。

如何将所有子图保存到一个图像?

1 个答案:

答案 0 :(得分:5)

执行axs[0].get_figure()

您正尝试在 numpy 数组上调用 matplotlib 方法。