r/Python • • Jan 10 '17

IPython shell with %matplotlib: the qt windows displaying figures disappear when I step away from the terminal application. Can this be fixed/is this typical behavior?

On my setup, figure windows created with the %matplotlib magic from an IPython shell (not entirely sure how this works) disappear after switching from my terminal application to any other running application, then back again. So, for example, if I am drawing a figure and want to check an /r/python thread in Chrome, after returning to my terminal application, I must re-declare the command plt.show().

Does this behavior sound atypical (something potentially wrong with my setup), or if it is typical, is there some possible workaround? Could this be unique to my installation/OS?

I am on MacOS Sierra, running the latest (just updated) versions of Anaconda and IPython. This problem is present using both iTerm2 and Terminal; does not seem to be related to the terminal application.

I tried asking in stackoverflow but they down voted my question without input, as is tradition.

7 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/schnadamschnandler Jan 12 '17 edited Jan 12 '17

Well I decided to methodically go through different combinations of ipython and jupyter qtconsole options, and here are the maddeningly and fascinatingly inconsistent results, using either command-line arguments, magic commands after IPython loads, or some combination of both:

FOR IPYTHON TERMINAL:

GUI SPEC:

--gui=qt, %matplotlib qt: after trying to declare figure, get "missing 1 required positional argument: 'figure'" (um... what?)

--gui=qt, --matplotlib=qt: get "no module named PyQt4"

--gui=qt, %matplotlib qt5: success; different window format than osx, with save dialogue offering filetype choice

--gui=qt, --matplotlib=qt5: success; same as above

--gui=qt, %matplotlib osx: success; window pops up as separate application

--gui=qt, --matplotlib=osx: QApplication window NEVER STARTS; fig appears as popup/part of terminal application, does not have its own "window"

NO GUI SPEC:

--matplotlib=qt5 OR %matplotlib qt5: success

--matplotlib=qt OR%matplotlib qt: get "no module named PyQt4"

--matplotlib=osx OR %matplotlib osx: QApplication window NEVER STARTS; fig appears as temporary popup

FOR JUPYTER QTCONSOLE using jupyter qtconsole -- (args follow)

GUI SPEC:

--gui=qt, %matplotlib qt5: get "RuntimeError: Cannot activate multiple GUI eventloops"

--gui=qt, --matplotlib=qt5: works, creates QApplication window for figures (seriously... WHAT? then why the hell doesn't %matplotlib qt5 work?)

--gui=qt, --matplotlib=inline OR %matplotlib inline: after trying to use plt.show(), get "matplotlib is currently using a non-GUI backend,"

--gui=qt, %matplotlib osx: get "RuntimeError: Cannot activate multiple GUI eventloops"

--gui=qt, --matplotlib=osx: works, but NO QApplication window; just a window-less popup

NO GUI SPEC:

--matplotlib=qt5 OR %matplotlib qt5: same as above, works

--matplotlib=osx OR %matplotlib osx: same as above, NO QApplication

--matplotlib=inline OR %matplotlib inline: after trying to use plt.show(), get "matplotlib is currently using a non-GUI backend,"

--matplotlib=qt: get "Eventloop or matplotlib integration failed. Is matplotlib installed?"

%matplotlib qt: get "no module named PyQt4"

FOR JUPYTER NOTEBOOK (no command-line options for notebook server, must specify in notebook cells)

%matplotlib inline: after trying to use plt.show(), get "matplotlib is currently using a non- GUI backend,"

%matplotlib notebook: works fine


So... maybe I should report this to the IPython developers? lol. I reported this to both the matplotlib and IPython issues pages on Github. Also I updated/reinstalled everything twice; qt, pyqt, matplotlib, qtconsole, etc.

I wonder if "gui" is not meant to be specified with "matplotlib"... like gui offers some sort of general interface that different modules can use?

I was told in another thread python is much easier to work with than Matlab, lol. I think there is some benefit to a pre-packaged, robust GUI compared to this open-source heap that continuously evolves.

1

u/flutefreak7 Jan 18 '17

Sorry for your pain!

Whoever said it was easier hasn't been down one of these rabbit holes before. The advantage with Python at times is that the rabbit hole is deeper and can lead to better treasure...

To be fair, the Matlab equivalent would be changing the Java runtime that Matlab uses and even that is benign compared to the complexity of matplotlib's many backends and the complexity of Python wrappers around half a dozen C and c++ based GUI framewords...

I hope this deep dive into the options was at least somewhat rewarding. Good luck finding a setup that works for you! It's not all this frustrating.