Add this near the beginning of the plotting script:
from matplotlib.backends.backend_pdf import PdfPages
pp = PdfPages('multipage.pdf')
Add this where you generate each panel:
pp.savefig()
Finally, add this at the end to close the file:
pp.close()Update: By default, Matplotlib pads acres of whitespace around the PDF. That's annoying when embedding PDF plots in a latex paper. Here's how to prevent the whitespace:
plt.savefig("output_plot.pdf", bbox_inches='tight', pad_inches=0.1)
No comments:
Post a Comment