4
votes

I'm writing a thousand plots to a PDF using matplotlib. I've already optimized the plotting code, ie. reusing figures/axes/lines and just changing the y data.

The bulk of the remaining time is spent in save_figure.

R, in comparison, seems to output a plot to PDF about 2x faster. Plots will all zero data seem to be even faster in R, while they're the same speed in Python.

I've set pdf.compression = 0, which makes a small improvement.

Tried rasterizing the data, it made no difference to plotting speed (although it used a ton of RAM).

Is there anything else I can try to speed up the matplotlib with PDF backend, or are there any alternative backends I should consider? I'm trying to beat R.

Thanks!

1
Are you tied to pdf or can you try eps/svg? Are you tied to vector graphics? - tacaswell
Not tied to vector graphics. Need a PDF in the end. Other formats are an option if they're significantly faster, but would require a way to convert them to PDF in the end. - peu ping
You might try exporting to eps fig.savefig('blah.eps') and then epspdf. - tacaswell
You might try something like this: gist.github.com/astrofrog/1453933 - G. Poore

1 Answers

0
votes

Have to tried pyreport from Gael Varoquaux? You call it on your script, it then collects all calls to pylab.show(), makes a png of each and then creates a PDF from it.

It uses Latex in the end, so you'll need this. But I expect this might be faster, as PDF creation is delegated to Latex.