Matplotlib figure to PDF without saving

前端 未结 3 2184
独厮守ぢ
独厮守ぢ 2021-02-11 04:10

I have to create a group of matplotlib figures, which I would like to directly present in a PDF report without saving them as a file.

The data for my plots is stored in

3条回答
  •  我寻月下人不归
    2021-02-11 05:07

    using my package autobasedoc https://pypi.org/project/autobasedoc/ your example would look like that:

    from autobasedoc import autorpt as ar
    from autobasedoc import autoplot as ap
    
    @ap.autoPdfImg
    def my_plot(index, row, canvaswidth=5): #[inch]
        fig, ax = ap.plt.subplots(figsize=(canvaswidth,canvaswidth))
        fig.suptitle(f"My simple plot {index}", fontproperties=fontprop)
        ax.plot(row['Xvalues'], row['Yvalues'],label=f"legendlabel{index}")
        return fig
    
    doc = ar.AutoDocTemplate(pageName)
    
    content = []
    
    for index, row in myDataFrame.iterrows():
        content.append(my_plot(index, row))
    
    doc.build(content)
    

提交回复
热议问题