gpt4 book ai didi

python - 将带有子图的 Pandas 图保存到一个文件中

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:19 28 4
gpt4 key购买 nike

我正在根据以下数据框在 pandas/jupyter notebook 中创建子图

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' object has no attribute 'get_figure'

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

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

最佳答案

执行axs[0].get_figure()

您正在尝试在 numpy 数组上调用 ma​​tplotlib 方法。

关于python - 将带有子图的 Pandas 图保存到一个文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47793985/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com