Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using reportlab to build PDF with vector-based graphs generated by matplotlib

I'm trying to build PDF-documents on the server-side in a Django-Installation using reportlab. These documents should contain several graphs which are to be created with matplotlib.

I already figured out how to make reportlab use matplotlib's images without dumping them to the filesystem temporarily by passing PIL-Image objects directly to the Image()-flowable. This works surprisingly well for rasterized images formats like PNG.

Now, the icing on the cake would be able to embed vector based graphics (like SVG).

I used svglib to convert SVGs generated by matplotlib to reportlab graphic objects but unfortunately svglib does omit the tickmarks and axis labels. On some graphs it fails in general.

Do you have any ideas?

like image 772
jnns Avatar asked Mar 18 '11 00:03

jnns


2 Answers

This page has a solution that I haven't had a chance to test myself yet: https://web.archive.org/web/20120725125858/http://lateral.netmanagers.com.ar/weblog/posts/BB753.html

like image 181
Greg Baker Avatar answered Nov 06 '22 21:11

Greg Baker


You can generate matplotlib graphics as pdf and use pdfrw to embed it in reportlab canvas as described in this answer

like image 35
Mohammad Alhashash Avatar answered Nov 06 '22 21:11

Mohammad Alhashash