stared / livelossplot

Live training loss plot in Jupyter Notebook for Keras, PyTorch and others
https://p.migdal.pl/livelossplot
MIT License
1.29k stars 142 forks source link

Need help to force the "inline" matplotlib backend when running scripts from Jupiter notebook #13

Closed sebma closed 5 years ago

sebma commented 6 years ago

Hi,

I'd like my script to automatically change the backend back to "inline" when it is run by Jupiter.

I tried this but it does not work (in practice) :

# If the script is not run by python but by jupyter and is using a different backend then "inline"
if matplotlib.get_backend() != 'Qt5Agg' and ( 'inline' not in matplotlib.get_backend() ) :
    print("=> BEFORE: matplotlib backend = <%s>" % matplotlib.get_backend() )
    matplotlib.use('module://ipykernel.pylab.backend_inline',warn=False, force=True) # <=> %matplotlib inline
    import matplotlib.pyplot as plt
    print("=> AFTER: matplotlib backend = <%s>" % matplotlib.get_backend() )

I get this (which theoretically is correct) :

=> BEFORE: matplotlib backend = <nbAgg>
=> AFTER: matplotlib backend = <module://ipykernel.pylab.backend_inline>

But in practice, the "inline" backend is not applied.

Can you help me ?

stared commented 6 years ago

@sebma I wish I knew how to do that.

If you learn how to do so, make sure to share it here!

stared commented 5 years ago

@sebma Since there is no progress in the last year, I close that. Open for opening in case of Pull Requests.