在 python pandas 中,如何保存“网格图”?

2024-05-23

我对 pandas 绘图工具很陌生,在文档中,以下命令非常方便:

myplot = rts.ret.hist(bins=50, by=rts.primary_mic)

然而,当我尝试从图中获取图形参考并保存它时,问题就出现了:

myfigure = myplot.get_figure()
AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'

我的理解是, rts.ret.hist(bins=50) 返回一个绘图对象,而 rts.ret.hist(bins=50) 返回一个数组对象。

在这种情况下我应该如何保存我的身材?

有什么线索吗?

thanks!


要保存数字,您可以使用plt.savefig:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.DataFrame(
    [(1, 2), (1, 3), (1, 4), (2, 1), (2, 2)], columns=['col1', 'col2'])
df.hist(bins=4, by=df['col1'])
plt.savefig('/tmp/out.png')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 python pandas 中,如何保存“网格图”? 的相关文章

随机推荐