2

How to save print output as well as plots in python to a single file in whichever output file format, be it .txt, .html, .pdf, etc. in an automated fashion? Since I will be doing this for thousands of outputs and plots, is there a python command I can use.

I know we can save them separately using python commands, but is there a python command to save them together in the same order that they are outputted, for example how they appear in a Jupyter notebook together as shown below. The format of the file in which they are saved does not matter as long as there is a way to save both together (ideally file format should not be very memory intensive, but that is secondary).

Print output as well as plot output in the same output file.

This is so that I can open the file later in a folder and the output is saved for me to always access later. If there is a lot of output Jupyter notebook unfortunately crashes, corrupting the file and making the code irrecoverable.

3 Answers 3

0

jupyter notebook have option "file" - download as" you can save as HTML and insert HTML code fragment for it.

1
  • I would like to automate the process since I will be doing this for hundreds of runs. May 9, 2021 at 21:36
0

So I found out that this is in fact a much bigger question and problem I had originally thought and the answer is much bigger and non-conventional than I had thought.

The open source platform MLflow (https://mlflow.org/) for machine learning lifecycle does this, and it does a better job than just keeping the plots and text output. It does this by storing the runs as well as saving the plots and outputs as artifacts. Further, a lot of my outputs were the different performance metrics and hyperparameters, which MLflow provides a simple method to store them for the different runs.

This is in fact what I was trying to do and kind of solves the underlying problem I was having of storing the output and the plots in one central location where they could be later accessed.

Thanks for all the help everyone. I appreciate it.

0

In jupyter notebook you can save it in multiple ways like pdf, ipynb etc. Saving your edits is simple. There is a disk icon in the upper left of the Jupyter tool bar. Click the save icon and your notebook edits are saved. It's important to realize that you will only be saving edits you've made to the text sections and to the coding windows. On the course website in Chromium, right-click on the . ipynb file you want to download, and select Save link as... In the Save File dialog that appears, make sure to save the . ipynb file

if you want to save in form of pdf then try opening the jupyter notebook in chrome and click right and print and save as pdf.

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.