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

Skip to content

matplotlib 1.5 compatibility with wxPython #5737

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
moonshoes87 opened this issue Dec 24, 2015 · 8 comments
Closed

matplotlib 1.5 compatibility with wxPython #5737

moonshoes87 opened this issue Dec 24, 2015 · 8 comments
Labels
GUI: wx status: needs clarification Issues that need more information to resolve.
Milestone

Comments

@moonshoes87
Copy link
Contributor

I'm running into a strange compatibility problem between wxPython and matplotlib.

import wx
import pylab
app = wx.App(False)
app.frame = wx.Frame(None)
app.frame.Centre()
app.frame.Show()

With matplotlib 1.5.0 or higher, this code will not run -- it hangs with no error on:

app = wx.App(False)

If I comment out "import pylab", it works fine. "import matplotlib" does not cause an error, but "import matplotlib.pyplot as plt" does.

With matplotlib 1.4.2, this code works fine as is, including the pylab import. This is with wxPython 3.0.2.0 and on OSX El Capitan.

I've looked for possible changes here: http://matplotlib.org/1.5.0/api/api_changes.html, but nothing appears relevant.

Any ideas about what's gone wrong?

@jenshnielsen
Copy link
Member

Sorry for not responding on this earlier. It seems to work if I explicitly set the WX/WXAgg backend before importing pylab

import wx
import matplotlib
matplotlib.use('WXAgg')
import pylab
app = wx.App(False)
app.frame = wx.Frame(None)
app.frame.Centre()
app.frame.Show()

@jenshnielsen
Copy link
Member

It's likely that this is related to the work in #3421 that enabled support for WXPython phoenix

@tacaswell tacaswell added this to the Critical bugfix release (1.5.1) milestone Jan 5, 2016
@tacaswell
Copy link
Member

If you do

from __future__ import print_function
import matplotlib.pyplot as plt
import matplotlib
print(matplotlib.get_backend())

what do you get?

My suspicion here is that you are importing wx, it may or may not be installing the input hook, and then pylab imports some other gui framework which install's it's input hook. Your wx app then sets up waits for it's event loop to be run (which will never happen as python is letting the other event loop run).

@tacaswell tacaswell added status: needs clarification Issues that need more information to resolve. not a blocker labels Jan 7, 2016
@moonshoes87
Copy link
Contributor Author

I get 'Qt4Agg' as the default backend.

If I set the backend as 'WXAgg' before importing pylab as jenshnielsen suggested, the error happens as before.

@jenshnielsen
Copy link
Member

Can you try 1.5.1rc1? I can reproduce the hanging with 1.5.0 but not with 1.5.1rc1

@tacaswell tacaswell modified the milestones: Critical bugfix release (1.5.1), critical bug fix (1.5.2) Jan 10, 2016
@moonshoes87
Copy link
Contributor Author

My original code still fails with 1.5.1. However, if I add matplotlib.use('WXAgg'), then all works as expected.

@jenshnielsen
Copy link
Member

In your original example you will import both WX and Qt4 since matplotlib defaults to the Qt4Agg backend and you import WX. Importing more than one GUI framework is unsupported and will in general lead to wrong behaviour. If you want to use matplotlib within a WX app you should make sure that it runs with the WX backend.

@jenshnielsen
Copy link
Member

I think this can close, it looks like this is only triggered when more than one gui backend is involved is an unsupported way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI: wx status: needs clarification Issues that need more information to resolve.
Projects
None yet
Development

No branches or pull requests

4 participants