如何保存用“pandas.DataFrame.plot"创建的图像? [英] How to save image created with 'pandas.DataFrame.plot'?

查看:91
本文介绍了如何保存用“pandas.DataFrame.plot"创建的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试从pandas.core.series.Series"对象中保存使用pandas.DataFrame.plot"创建的绘图图像时:

When trying to save plot image created with 'pandas.DataFrame.plot' from ' pandas.core.series.Series' object :

%matplotlib inline
type(class_counts) # pandas.core.series.Series
class_counts.plot(kind='bar',  figsize=(20, 16), fontsize=26)

像这样:

import matplotlib.pyplot as plt
plt.savefig('figure_1.pdf', dpi=300)

导致空的 pdf 文件.如何保存用pandas.DataFrame.plot"创建的图像?

results in empty pdf file. How to save image created with 'pandas.DataFrame.plot'?

推荐答案

试试这个:

fig = class_counts.plot(kind='bar',  figsize=(20, 16), fontsize=26).get_figure()

fig.savefig('test.pdf')

这篇关于如何保存用“pandas.DataFrame.plot"创建的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆