-1

I need to have a report in PDF with a lot of plots coded in python. Most of them will be created with matplotlib within a loop, but I would need also to include pandas plots and dataframes (the whole view) and seaborn plots. Right now I have explored the following solutions:

  • PythonTex. I have already used it for other projects, but it would consume a lot of time because you have to write \pythontexprint for each plot you want to display.
  • Use savefig command of matplotlib package in every iteration of the loop and save all the plots as image for inserting all in Latex later. That would be very time consuming choice too. Other option is with that command save the plots as pdf and then merge all the pdfs. That would create an ugly report since the plots are not going to fit the whole page.
  • Use RStudio with reticulate for creating a Markdown report. The problem here is that I would need to learn reticulate functionality, thus spending time. As far as I know, PyPDF does not fit my needs.
  • Create a jupyter notebook and then try to export it to a PDF. Once again, I do not know how to use jupyter notebook and I read that I would have to convert first to html and then to pdf.
  • Solutions from here: Generating Reports with Python: PDF or HTML to PDF However, the question is from three years ago and it might better options nowadays.

So my question is the following: is there any easy and quick way of getting all those plots (if it is along the code which generates them even better) in a PDF with a decent aspect?

  • ReportLab works well. – Eric Shain Sep 9 '18 at 14:19
0

If you already know Python, Pandas & Matplotlib then Jupyter Notebooks are quick and easy to learn. You can tell Jupyter to render a Notebook to pdf without you needing to do any manual intervention in HTML.

From the above that a number of your plots are generated from the same data and with the same mechanism but with different parameters so I would suggest converting that to a parameterised function that returns a plot and then having a cell that calls this for each required plot. You can also interleave cells of Markdown to describe the methodology and the meaning of the following plots.

You may wish to take a look at Jupyter Lab for a more modern user interface.

Some further reading can be found at:

and I especially recommend taking a look at the second of these two.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.