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

Skip to content

[Bug]: Matplotlib crashes using Figure Options gui with QT5Agg backend on Windows 10 running Spyder #22543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Jesperten opened this issue Feb 23, 2022 · 17 comments

Comments

@Jesperten
Copy link

Jesperten commented Feb 23, 2022

Bug summary

Using the QT5Agg backend with the 3.5.1 version of Matplotlib crashes after pressing 'ok' in the Figure Options GUI. This happens regardless of doing any changes to the plot or not.
The only way to bring Matplotlib back to life, is to restart the python kernel.

Code for reproduction

import matplotlib.pyplot as plt
plt.plot([1,2],[1,2])

# Then open Figure Options, and press 'ok'

Actual outcome

Plot window becomes inactive, and does not response to any input.

Expected outcome

No changes to the plot window whatsoever. The window should continue being responsive.

Additional information

I am running my scripts in Spyder, which is where I am experiencing this bug.

Operating system

Windows 10

Matplotlib Version

3.5.1

Matplotlib Backend

Qt5Agg

Python version

3.9.10

Jupyter version

No response

Installation

conda

@oscargus
Copy link
Member

Can you try running the scripts from a terminal? I experience similar problems and it seems to work better from a terminal. Still a problem of course, but would be interesting to narrow it down. It may still be a Matplotlib issue, but also a Spyder/spyder-kernel/IPython/ipykernel problem...

@Jesperten
Copy link
Author

Hi. thanks for responding so fast.
It works well from a terminal running in the same conda-environment as I use from Spyder.
So it might be related to Spyder/iPython kernel issue...

@oscargus
Copy link
Member

Here are some related issues:
ipython/ipykernel#775
spyder-ide/spyder#17172

Not explicitly like this, but at least indicating that there are some problems with the related code and that it is not really clear who should change what... But for sure worthwhile digging into!

@oscargus oscargus changed the title [Bug]: Matplotlib crashes using Figure Options gui with QT5Agg backend on Windows 10 [Bug]: Matplotlib crashes using Figure Options gui with QT5Agg backend on Windows 10 running Spyder Feb 23, 2022
@oscargus
Copy link
Member

It may be that this is fixed by #22202

@QuLogic
Copy link
Member

QuLogic commented Apr 8, 2022

Is there some kind of backtrace, or does it simply die?

@Jesperten
Copy link
Author

It simply just dies, when I try to open the menu.

@raphaelquast
Copy link
Contributor

raphaelquast commented May 18, 2022

hey, I thought I'll add my problem here since it seems to be quite related... (and I'm using matplotlib v3.5.2)
On my side, the Qt5Agg gui becomes irresponsive if I click on the button to adjust the axis limits while there is more than 1 axes in the plot... (plt.subplots(2) or ax.twinx() show the same behaviour)

... and it also simply dies (I can't even close or resize the gui any more)

mpl_issue

[edit by @tacaswell to put gif in a detalis fold because it was making me slightly motion sick!]

@Jesperten
Copy link
Author

I experience the exact same thing.
The funny thing is that if you manage to hit ok in the pop-up window, before it crashes, it actually stays functional.
So it might be related to the initial window, where you can select which plot you want to configure.

@tacaswell
Copy link
Member

This looks like there is something wrong with the input hook inside of the terminal that is being hosted by spyder. When you see things like "I click on the window and nothing happens" or "I resize and just get blank space padding the graph" that is usually because (for what ever reason) the UI event loop is not running. Hence the windowing system is sending to your application ("user clicked", "user clicked",...) and your application is just being like "yup, good to know, put it on the queue" but not actually doing anything about the input.

If in the terminal you run plt.show(block=True) do thing come back to life / work ?

@raphaelquast
Copy link
Contributor

hey, thanks for the response!

I checked and using plt.show(block=True) or a plain plt.show() does not help.
... also I get the very same behavior in a basic python console... so spyder does not seem to have anything to do with it.

However, I noticed that this is only an issue if interactive mode is on (e.g. plt.ion() is called).
In non-interactive mode, all works as expected.

(click) for a gif showing the behavior directly from a python-console

mpl_issue

@tacaswell
Copy link
Member

The behavior of plt.show() depends on the value of plt.isinteractive() (which is stored in an rcparam). For debugging please explicitly set block to True or False just to be sure we are decoupling from any underlying global state.

Can you also test in an IPython shell (as oppossed to plain python) and make sure you are using prompttoolkit (rather then readline) for the prompt?

This is starting to get into the realm of https://matplotlib.org/stable/users/explain/interactive_guide.html and how the event loop is (or is not) managed.

@raphaelquast
Copy link
Contributor

Hey, I can confirm that if I directly use an IPython 7.31.1 shell all works as expected !
(from what I read, prompttoolkit is used from v5.0 on)
The strange thing is that Spyder is using the same ipyhton version but here the error is happening just as with the plain python shell.

@tacaswell
Copy link
Member

Hey, I can confirm that if I directly use an IPython 7.31.1 shell all works as expected !

I think this show that this is fundamentally an issue with spyder, readline, pyqt/pyside and the interaction with the event loop. It is possible that there is something we could do differently on the Matplotlib side to work around this, but I think we would need guidance from down-stream about what those changes will be.

I would point to spyder-ide/spyder#4367 which re-points the problem to the IPython Qt console. I strongly suspect that this is another version of this.

I'm going to close this issue here as

  1. the issue seems isolated to usage only with in the qt ipython console
  2. the integration of the event loop that hosts the Matplotlib figures (any toolkit and and downstream use) is the primary responsibility of down stream tools. That said we will definitely take any patches that make that integration work better, but failure to work with a given integration is not a bug.

Sorry to play hot-potato 😞 .


attn @cordoba12

@tacaswell tacaswell closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 2022
@raphaelquast
Copy link
Contributor

hey, ok sounds reasonable...

just as a final comment...
i think there might be 2 different things in question here

  1. the fact that spyders ipython console has the issue but a "plain ipython console" does not
  2. the fact that the same error occurs in a plain python console

While the first one is certainly on spyder (or somewhere further down the road), the second part remains puzzling ...
(e.g. the issue is not isolated to a qt ipython console)

@tacaswell
Copy link
Member

the fact that the same error occurs in a plain python console

fair, re-opening.

@tacaswell tacaswell reopened this May 23, 2022
@jklymak
Copy link
Member

jklymak commented May 23, 2022

I'll re-close since the original issue was Spyder only. @raphaelquast can you open a new reproducible issue with the problem that you can reproduce without Spyder? Thanks for your understanding.

@raphaelquast
Copy link
Contributor

@jklymak @tacaswell moved to new issue #23103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants