繁体   English   中英

将pandas.DataFrame.hist与多个轴一起保存在一个图中

[英]Save pandas.DataFrame.hist with multiple axes in one figure

我有一个包含24列的pandas数据pandas.DataFrame.hist ,并且使用函数pandas.DataFrame.hist生成带有一些子图的图形。

plot = df.hist(figsize = (20, 15))
plot


array([[<matplotlib.axes._subplots.AxesSubplot object at 0x0000000018D47EB8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001C1200B8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001C1EADD8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001C20A4A8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B61AB38>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x000000001B61AB70>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B671898>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B698F28>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B6C85F8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B6F2C88>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x000000001B723358>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B74A9E8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B77B0B8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B7A1748>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B7C8DD8>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x000000001B7F84A8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B821B38>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B853208>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B87B898>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B8A2F28>],
       [<matplotlib.axes._subplots.AxesSubplot object at 0x000000001B8D35F8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B8FAC88>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B92C358>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B9549E8>,
        <matplotlib.axes._subplots.AxesSubplot object at 0x000000001B9850B8>]],
      dtype=object)

问题是,当我尝试将此图形保存到单个PNG文件中时,出现错误

plot.savefig(os.path.join(folder_wd, folder_output, folder_dataset,'histogram.png'))

AttributeError:“ numpy.ndarray”对象没有属性“ savefig”

到目前为止,我所检查的文章均未提供解决方案

熊猫可视化指南 StackOverflow

savefig不是的方法plot由返回的对象df.hist 尝试以下

import matplotlib.pyplot as plt

# rest of your code

plot = df.hist(figsize = (20, 15))
plt.savefig(os.path.join(folder_wd, folder_output, folder_dataset,'histogram.png'))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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