Issue
On my setup, figure popup 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 a StackOverflow post in Chrome, after returning to my terminal application, I must re-declare the command plt.show()
to re-open the popup windows.
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.
Note: My goal is to replicate the behavior of generating plots with matlab -nodesktop
in the terminal, which creates persistent figure windows from the Matlab application.
Solution
Edit: 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 (in short, one should use ipython --matplotlib=qt5
):
For iPython terminal:
Specify --gui
:
--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"
Without specifying GUI:
--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; figures appear as temporary popup
For Jupyter QTConsole (i.e. jupyter qtconsole ...
)
Specify --gui
:
--gui=qt
,%matplotlib qt5
: get "RuntimeError: Cannot activate multiple GUI eventloops"--gui=qt --matplotlib=qt5
: works, and creates QApplication window for figures (seriously... what? then why doesn't%matplotlib qt5
work?)--gui=qt --matplotlib=inline
or%matplotlib inline
: after trying to useplt.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; again, just a window-less popup.
Without specifying GUI:
--matplotlib=qt5
or%matplotlib qt5
: same as when we specified GUI: works--matplotlib=osx
or%matplotlib osx
: same as when we specified GUI: works, but no QApplication window--matplotlib=inline
or%matplotlib inline
: after trying to useplt.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"
Original answer:
Just use
%gui qt
magic, followed by any %matplotlib <backend>
that is GUI-based; on a Mac, I used %matplotlib osx
. The gui magic creates a persistent Qt window as its own QApplication, instead of the temporary popup windows.
Answered By - Luke Davis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.