Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding plots to a pdf file

My code reads all the text file in the folder, turns it into an array and plots a histogram of each data using a for cycle, pretty simple stuf, but I want to save all it returns, all the histograms into a single pdf file. I know the function:

plt.savefig('file.pdf')

works but since it's in a for cycle it will only save the last one, I mean it overwrites on it. Is there a function to add the other histograms or should I change the code?

like image 238
bajotupie Avatar asked Feb 21 '26 00:02

bajotupie


1 Answers

You essentially have two options.

1. Create multiple pdf files, merge them afterwards

  • Merge PDF files
  • append page to existing pdf file using python

2. Write all plots directly to a single pdf file.

  • Example from the matplotlib page: http://matplotlib.org/examples/pylab_examples/multipage_pdf.html

  • Output a Document (preferably a PDF) from Python

  • why does no picture show

like image 150
ImportanceOfBeingErnest Avatar answered Feb 25 '26 01:02

ImportanceOfBeingErnest



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!