I would like to use matplotlib to generate a number of PDF files. My main problem is that matplotlib is slow, taking order of 0.5 seconds per file.
I tried to figure out why it takes so long, and I wrote the following test program that just plots a very simple curve as a PDF file:
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
X = range(10)
Y = [ x**2 for x in X ]
for n in range(100):
fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111)
ax.plot(X, Y)
fig.savefig("test.pdf")
But even something as simple as this takes a lot of time: 15–20 second in total for 100 PDF files (modern Intel platforms, I tried both Mac OS X and Linux systems).
Are there any tricks and techniques that I can use to speed up PDF generation in matplotlib? Obviously I can use multiple parallel threads on multi-core platforms, but is there anything else that I can do?