I'm using
import matplotlib as mpl
mpl.use ('pdf')
from matplotlib.backends.backend_pdf import PdfPages
...
self.pdf = PdfPages(file_name)
...
self.pdf.savefig (self.fig)
plt.close()
...
pdf.close()
This works fine, but now I want to try pgf.
If I add:
from matplotlib.backends.backend_pgf import FigureCanvasPgf
mpl.backend_bases.register_backend('pdf', FigureCanvasPgf)
at the beginning, then it chokes on the savefig (self.fig):
Traceback (most recent call last):
File "./plot_stuff2.py", line 362, in <module>
the_plot.finish (args, opt, time, res)
File "./plot_stuff2.py", line 157, in finish
self.pdf.savefig (self.fig)
File "/home/nbecker/.local/lib/python2.7/site-
packages/matplotlib/backends/backend_pdf.py", line 2297, in savefig
figure.savefig(self, format='pdf', **kwargs)
File "/home/nbecker/.local/lib/python2.7/site-packages/matplotlib/figure.py",
line 1421, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/home/nbecker/.local/lib/python2.7/site-
packages/matplotlib/backend_bases.py", line 2220, in print_figure
**kwargs)
File "/home/nbecker/.local/lib/python2.7/site-
packages/matplotlib/backend_bases.py", line 2060, in _print_method
return print_method(*args, **kwargs)
File "/home/nbecker/.local/lib/python2.7/site-
packages/matplotlib/backends/backend_pgf.py", line 869, in print_pdf
raise ValueError("filename must be a path or a file-like object")
ValueError: filename must be a path or a file-like object
I know I had this working some time in the past, what's the trick to making
multi-page pdf with pgf?