【问题标题】:How to save image created with 'pandas.DataFrame.plot'? [duplicate]如何保存使用“pandas.DataFrame.plot”创建的图像? [复制]
【发布时间】:2018-01-04 16:26:31
【问题描述】:

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

%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”创建的图像?

【问题讨论】:

    标签: python pandas plot


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-21
      相关资源
      最近更新 更多