I have a special key (q) mapped to close the current figure. Using matplotlib 1.4.3 I can not close the current figure with this keymap and under the backend MacOSX. Specifically when I press the q key the keypress is sent to the shell instead.
I am currently on OSX Yosemite. My quick fix was to choose a different backed, Qt4Agg.
If I put keymap.quit : q in matplotlibrc and do the following:
$ python
Python 2.7.8 (default, Feb 27 2015, 23:52:58)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.use("macosx")
>>> from pylab import *
>>> figure()
<matplotlib.figure.Figure object at 0x1043e67d0>
>>>
then the figure closes if I click on the figure (to make it active) and press 'q'.
If I don't click on the figure first (so the terminal keeps key input), then pressing 'q' the key press is sent to the terminal instead. Do you get the same? As far as I know, this is the desired behavior.
The screenshot suggests that your Python is not installed as a framework.
See the section "Building and using a framework-based Python on Mac OS X" in the README in the subdirectory "Mac" of the Python source distribution for a full explanation.
Did you install Python yourself, or are you using a pre-compiled version of Python?
@scottsievert Can you have a look in your pyconfig.h to see if WITH_NEXT_FRAMEWORK is defined? It should contain the following line:
#define WITH_NEXT_FRAMEWORK 1
To find pyconfig.h on your computer, you can use
OK thanks. Indeed your Python is not installed as a framework. Matplotlib should have noticed that when it was compiled. Did you compile matplotlib yourself, or did you use a precompiled matplotlib?
I used the version of mpl that came with Anaconda. I installed Anaconda long before this bug appeared, and the only real changes I can think of was that I upgraded anaconda (using conda upgrade anaconda) and developed a package which required I play with pandoc/markdown.
Aha, got it! This is perhaps a different issue -- it is present under a freshly installed version of anaconda.
I switched Python shells from IPython to ptipython. My keybinding 'q' works only when I use IPython. To show that, I have run the script under different python interpreters (and get different behaviors!):
To be clear, while I was running this, by backend was MacOSX on OSX 10.10 under a freshly installed Anaconda. Under python, ptpython and ptipython, the keymap q is sent to the shell and not to the current figure window.
@scottsievert I have added a run-time check to the MacOSX backend to make sure Python is installed as a framework (see the pull request). On Python2, the same check is also available as part of the MacOS module, which is part of the Python standard library. Could you try the following with python/ipython/ptpython/ptipython:
>>>importMacOS>>>MacOS.WMAvailable()
This should return True if python is installed as a framework, and False otherwise.
Activity
tacaswell commented on Apr 23, 2015
attn @mdehoon
WeatherGod commented on Apr 23, 2015
Do you have other keys mapped to actions? Do they work? I wonder if this is
really a terminal/figure window focus issue.
On Thu, Apr 23, 2015 at 10:51 AM, Thomas A Caswell <notifications@github.com
mdehoon commented on Apr 24, 2015
If I put keymap.quit : q in matplotlibrc and do the following:
$ python Python 2.7.8 (default, Feb 27 2015, 23:52:58) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib >>> matplotlib.use("macosx") >>> from pylab import * >>> figure() <matplotlib.figure.Figure object at 0x1043e67d0> >>>then the figure closes if I click on the figure (to make it active) and press 'q'.
If I don't click on the figure first (so the terminal keeps key input), then pressing 'q' the key press is sent to the terminal instead. Do you get the same? As far as I know, this is the desired behavior.
stsievert commented on Apr 24, 2015
I think this is a terminal/plot focus issue. When I click on the plot, both my terminal and the figure are active (screenshot).
I have tried other keymaps. They do not work with the MacOSX backend but do work with the Qt4Agg backend.
Is this problem unique to my system? I see this behavior even under a virtualenv after activating and running pip install matplotlib.
mdehoon commented on May 1, 2015
The screenshot suggests that your Python is not installed as a framework.
See the section "Building and using a framework-based Python on Mac OS X" in the README in the subdirectory "Mac" of the Python source distribution for a full explanation.
Did you install Python yourself, or are you using a pre-compiled version of Python?
stsievert commented on May 19, 2015
This issue can be close if it's local to my machine. I have solved it by switching backends.
(I'm using Anaconda)
mdehoon commented on May 19, 2015
Let's not close this issue yet. I'd like to find out why matplotlib didn't notice that Python was not installed as a framework.
mdehoon commented on May 20, 2015
@scottsievert Can you have a look in your pyconfig.h to see if WITH_NEXT_FRAMEWORK is defined? It should contain the following line:
#define WITH_NEXT_FRAMEWORK 1
To find pyconfig.h on your computer, you can use
then pyconfig.h will be in the directory sys.prefix + /include/python2.7.
Also, can you let me know what sys.prefix returns in your case?
stsievert commented on May 20, 2015
The relevant part of pyconfig.h:
I just installed a fresh version of Anaconda. It worked after that fresh install.
mdehoon commented on May 20, 2015
OK thanks. Indeed your Python is not installed as a framework. Matplotlib should have noticed that when it was compiled. Did you compile matplotlib yourself, or did you use a precompiled matplotlib?
stsievert commented on May 20, 2015
I used the version of mpl that came with Anaconda. I installed Anaconda long before this bug appeared, and the only real changes I can think of was that I upgraded anaconda (using conda upgrade anaconda) and developed a package which required I play with pandoc/markdown.
stsievert commented on May 20, 2015
Aha, got it! This is perhaps a different issue -- it is present under a freshly installed version of anaconda.
I switched Python shells from IPython to ptipython. My keybinding 'q' works only when I use IPython. To show that, I have run the script under different python interpreters (and get different behaviors!):
To be clear, while I was running this, by backend was MacOSX on OSX 10.10 under a freshly installed Anaconda. Under python, ptpython and ptipython, the keymap q is sent to the shell and not to the current figure window.
mdehoon commented on May 24, 2015
@scottsievert I have added a run-time check to the MacOSX backend to make sure Python is installed as a framework (see the pull request). On Python2, the same check is also available as part of the MacOS module, which is part of the Python standard library. Could you try the following with python/ipython/ptpython/ptipython:
This should return True if python is installed as a framework, and False otherwise.
stsievert commented on May 24, 2015
mdehoon commented on Jun 1, 2015
Thanks! This was fixed by pull request #4452 . The new code effectively does the same as WMAvailable().
This issue can be closed.
tacaswell commented on Jun 2, 2015
Closed by #4452