Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib savefig into different pages of a PDF

I have a lengthy plot, composed o several horizontal subplots organized into a column.

When I call fig.savefig('what.pdf'), the resulting output file shows all the plots crammed onto a single page.

Question: is there a way to tell savefig to save on any number (possibly automatically determined) of pdf pages?

I'd rather avoid multiple files and then os.system('merge ...'), if possible.

like image 242
astabada Avatar asked Oct 17 '12 16:10

astabada


2 Answers

I haven't tried myself, but in the matplolib faq there are some instruction to save plots in pdf in several pages.

  • FAQ http://matplotlib.org/faq/howto_faq.html#save-multiple-plots-to-one-pdf-file
  • Example http://matplotlib.org/examples/pylab_examples/multipage_pdf.html
like image 175
Pablo Navarro Avatar answered Sep 28 '22 00:09

Pablo Navarro


I suspect that there is a more elegant way to do this, but one option is to use tempfiles or StringIO to avoid making traditional files on the system and then you can piece those together.

like image 24
TimothyAWiseman Avatar answered Sep 27 '22 23:09

TimothyAWiseman