question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
tacaswellcommented, Mar 15, 2020

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__ to Figure in Matplotlib that then defers to a method on the canvas object. We would then put the correct methods on the canvas classes from inline (the static backend), nbagg (which we will hopefully be able to retire in the next year or two), and ipympl (the ipywidegts based notebook backend).

0reactions
westurnercommented, Apr 15, 2021
  • DOC: what do the docs for %matplotlib inline clarify?
Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot import name 'configure_inline_support - Stack Overflow
I reproduced problem with fresh installed Jupyter Notebook on Python 3.9 on Linux Mint . After updating matplotlib (to newest 3.4.1 ) it ......
Read more >
cannot import name 'configure_inline_support - splunktool
Importerror: Cannot Import Name 'Dedent' From 'Matplotlib. ... Although I don't regularly use Jupyter, I did test it by running jupyter notebook.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found