Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ianthomas23
Copy link
Collaborator

Possible fix for #14329.

With this change, the reproducers from the issue become:

$ ipython
<snip>

In [1]: import matplotlib.pyplot as plt; plt.set_loglevel("debug")

In [2]: %matplotlib tk
DEBUG:matplotlib.pyplot:Loaded backend TkAgg version 8.6.

and
Screenshot from 2024-02-12 12-44-30

It is still possible to call matplotlib.pyplot.switch_backend twice but only if you request %matplotlib inline, and the switch_backend is called with same correct backend twice. This isn't ideal but it doesn't cause any problems apart from being a little slower than necessary.

@Carreau Carreau added this to the 8.22 milestone Feb 16, 2024
@Carreau
Copy link
Member

Carreau commented Feb 16, 2024

Let's try.

@Carreau Carreau merged commit e60c06a into ipython:main Feb 16, 2024
@ianthomas23 ianthomas23 deleted the delay_import_mpl_inline branch February 16, 2024 10:45
Carreau added a commit that referenced this pull request Apr 15, 2024
Fixes #14401 which has been a bug in the 8.22.x and 8.23.x releases.

When I removed the multiple initialisation of Matplotlib backends in
#14330 it broke use of the following:
```bash
ipython --matplotlib
ipython --matplotlib=auto
ipython --pylab
ipython --pylab=auto
```
by failing to display Matplotlib plot. If you specify a particular GUI
event loop such as using
```bash
ipython --pylab=qt
```
then it was and is fine. So for anyone finding this, the workaround
until the next release is to specify a GUI loop rather than relying on
the auto selection.

I didn't notice this as I've been concentrating on moving the Matplotlib
backend logic from IPython to Matplotlib, and with those changes
(matplotlib/matplotlib#27948) the above use cases all work OK.

The fix is to reintroduce the early import of `matplotlib-inline` but
only if both the gui loop is not specified and the Matplotlib version is
before the movement of the backend logic across to it.

There are no explicit tests for this. In the future I will try to think
of some tests for some of this IPython-Matplotlib functionality that
don't involve installing complicated backend dependencies or adding
image comparison tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants