Jan-Hendrik Ewers Logo

How To Easily Export Figures From Your Jupyter Notebooks

February 10, 2022    jupyter python


Have a nice jupyter notebook with many many figures and don’t want to right click -> save every single one? Well nbconvert to the rescue (sort of).

nbconvert lets you convert your notebooks to other formats, but some formats don’t allow embedded images. So, to extract images we use a format that needs them to be stored as separate files.

python -m jupyter nbconvert --to markdown my_notebook.ipynb
[NbConvertApp] Converting notebook my_notebook.ipynb to markdown
[NbConvertApp] Support files will be in my_notebook_files/
[NbConvertApp] Making directory my_notebook_files
[NbConvertApp] Writing 288 bytes to my_notebook.md

$ ls my_notebook_files
my_notebook_1_0.png

Make sure to clean up the .md files afterwards!

Example

Here’s a simple y=sin(x) example. If I had plotted at a higher dpi with fig, ax = plt.subplots(dpi=300), the exported image would be better. The embedded example is just a simple screenshot.

before Embedded Image

before After export