import Image
import matplotlib.pyplot as plt
import io
from reportlab.pdfgen import canvas
from reportlab.lib.units import inch, cm
from reportlab.lib.utils import ImageReader
fig = plt.figure(figsize=(4, 3))
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
imgdata = io.StringIO()
fig.savefig(imgdata, format='png')
imgdata.seek(0)
Image = ImageReader(imgdata)
c = canvas.Canvas('test.pdf')
c.drawImage(Image, cm, cm, inch, inch)
c.save()
How to drawImage a matplotlib figure in a reportlab canvas?