Remove the necessity to run %matplotlib inline in Jupyter Notebooks by running configure_inline_support
See original GitHub issueCurrently, whenever a Jupyter Notebook is launched, the MPLBACKEND environment variable is set to module://ipykernel.pylab.backend_inline in init_gui from ipykernel.kernelapp.
While this sets matplotlib’s backend to inline, figures not created via pyplot will not be shown in the notebook output.
This is because the function configure_inline_support from python.core.pylabtools is never run. It is responsible for hooking a function that gets triggered whenever a matplotlib figure is the output of a cell. The function calls the figure’s canvas’s print_figure function and returns the raw bytes of the image.
This function configure_inline_support does get run when matplotlib.pyplot is imported and when %matplotlib inline is run.
Having to do either of these things can be eliminated by running configure_inline_support within init_gui after the shell is retrieved. I think the following could be enough:
from IPython.core.pylabtools import configure_inline_support
configure_inline_support(shell, 'module://ipykernel.pylab.backend_inline')
I’d be very excited to have this change and never worry about running %matplotlib inline again.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:8 (2 by maintainers)

Top Related StackOverflow Question
You do not want to import Matplotlib on notebook start up because if the user does not need it we should not waste the import time.
We also need to be sure that these changes do not break either nbagg or ipympl.
Steps 7-9 are the key steps for making the implicit display work.
Probably the right way to fix this is to add a
__repr_html__toFigurein Matplotlib that then defers to a method on the canvas object. We would then put the correct methods on the canvas classes frominline(the static backend),nbagg(which we will hopefully be able to retire in the next year or two), andipympl(the ipywidegts based notebook backend).%matplotlib inlineclarify?