首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用PdfPages python将多个绘图保存为pdf

使用PdfPages python将多个绘图保存为pdf
EN

Stack Overflow用户
提问于 2020-11-12 00:39:01
回答 1查看 119关注 0票数 0

我正在尝试保存我的输出(70+图形)从jyputer笔记本到pdf文件。没有错误或其他任何东西,但只导出了第一个图。有没有人能帮我弄明白出了什么问题?

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.backends.backend_pdf

pdf = matplotlib.backends.backend_pdf.PdfPages("output.pdf")
df_num = df.select_dtypes(include = ['float64', 'int64'])

with PdfPages(r'output.pdf') as export_pdf:
    fig = plt.figure(figsize=(12,12))
    for col in df_num.columns:
        hist = df_num[col].hist(bins=10)
        print("Plotting for column {}".format(col))
        plt.title("{}".format(col), fontsize=20) 
        plt.show()        
    export_pdf.savefig(fig)       
EN

回答 1

Stack Overflow用户

发布于 2020-11-12 02:39:16

好吧,最终我想通了。以下是我的解决方案:

代码语言:javascript
复制
with PdfPages(r'output_dist.pdf') as export_pdf:
    
    for col in df_f.columns:
        fig = plt.figure(figsize=(12,12))
        hist = df_f[col].hist(bins=10)
        print("Plotting for column {}".format(col))
        plt.title("{}".format(col), fontsize=20) 
        plt.show()
        
        export_pdf.savefig(fig)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64790486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档