Matplotlib has a lot of overhead for creating a shape, etc. even before saving it to pdf. Therefore, if your plots are similar, you can safely "tune" a lot by reusing elements, just as you will find in the animation examples for matplotlib.
You can reuse the shape and axes in this example:
import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt X = range(10) Y = [ x**2 for x in X ] fig = plt.figure(figsize=(6,6)) ax = fig.add_subplot(111) for n in range(100): ax.clear()
Please note that this does not help much. You can save a little more by reusing the lines:
line = ax.plot(X, Y)[0] for n in range(100):
This is almost twice as fast as the original example for me. This is only an option if you make similar stories, but if they are very similar, it can speed up a lot. matplotlib animation examples may inspire such optimization.
source share