本文介绍了在python pandas 中,如何保存“网格图"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对熊猫图设施很陌生,在文档中,以下命令非常方便:

i am quite new to pandas plot facilities, in the doc, the following command is really handy:

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

但是,当我尝试从绘图中获取图形参考并将其保存时,问题就来了:

however, the problems comes when i try to get a figure reference from the plot and save it:

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

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

what I understand is, rts.ret.hist(bins=50) returns a plot object, while rts.ret.hist(bins=50 returns an array object.

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

how should I save my figure in this case?

有任何线索吗?

谢谢!

推荐答案

要保存该图形,可以使用plt.savefig:

To save the figure, you could use 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')

这篇关于在python pandas 中,如何保存“网格图"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 16:32