Skip to content

Remove the necessity to run %matplotlib inline in Jupyter Notebooks by running configure_inline_support #12190

@tdpetrou

Description

@tdpetrou

Currently, 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.

Screen Shot 2020-03-13 at 8 26 34 PM

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions