[PYTHON] Dynamically generate graphs with matplotlib and embed in PDF with reporlab

It seems that it can be done via PIL.ImageFileIO.

It can be used when dynamically creating a PDF on the web and returning it.

from StringIO import StringIO
from PIL import ImageFileIO
import matplotlib.pyplot as plt
from reportlab.platypus import Image
 
buf = StringIO()
 
#plot your graphs
 
plt.save_figure(buf, format="png")
buf.seek(0)
im = ImageFileIO.ImageFileIO(buf)
 
flowable_image = Image(im) 

https://gist.github.com/kokardy/5967661

Recommended Posts

Dynamically generate graphs with matplotlib and embed in PDF with reporlab
Embed matplotlib graphs in Tkinter
Dynamically create tables in schema with Django, dynamically generate models
Animate multiple graphs with matplotlib
Visualize graphs with Japanese labeled edges in NetworkX and PyGraphviz / Gephi
Two ways to display multiple graphs in one image with matplotlib
[Python] font family and font with matplotlib
Heatmap with Dendrogram in Python + matplotlib
Easy to draw graphs with matplotlib
[Small story] How to save matplotlib graphs in a batch with Jupyter
Plot black and white graphs suitable for papers with matplotlib or pylab
A story about converting HTML to PDF with WeasyPrint + matplotlib and embedding graphs [Beginners learn python with a reference book]
Write SVG graphs with matplotlib on heroku
Display Japanese graphs with VS Code + matplotlib
PDF output with Latex extension in Sphinx
Separation of design and data in matplotlib
Graph trigonometric functions with numpy and matplotlib
I want to embed Matplotlib in PySimpleGUI
Try implementing Yubaba with Brainf * ck 512 lines (Generate and execute code in Python)