jovo
jovo

Reputation: 41

How to generate a Cocoa-recognized plot using matplotlib in Python on OS X (Leopard preferably)

I'm not sure exactly what is going on under the hood, but here is my setup, example code, and problem:

setup:

example code:

import numpy as np
import pylab as pl
x=np.random.normal(size=(1000,))
pl.plot(x)

problem:

I can't use the standard Mac OS X shorcuts to access the window generated by the plot command.

For example, I can't Command-Tab to the window. Thus, if the window is behind some other window, I need to mouse over to it! Command-W doesn't close it.

Obviously, this is unacceptable. It seems like perhaps running Lion instead of Leopard might fix this, but i haven't upgraded yet. I feel like the problem has something to do with iPython generating windows that aren't fully Cocoa-aware in some sense, but I really know very little so I'm not particularly confident in this hypothesis.

Thus, any ideas on how to either resolve or get around this issue would be much appreciated.

Upvotes: 4

Views: 402

Answers (2)

user3148185
user3148185

Reputation: 524

I experienced the same annoyance with my Anaconda installation of Python 2.7.10 on Mac OS X Yosemite 10.10.5. One solution I found was to change the backend to Mac OS X or Qt4Agg by creating a ~/.matplotlib/matplotlibrc file with the line:

backend: MacOSX

or

backend: Qt4Agg

Now I can easily get to the plot window with Application switcher using Command - Tab and close it with Command - W .

Upvotes: 0

Rob Keniger
Rob Keniger

Reputation: 46020

From the description on the iPython page, it looks like Python uses Qt to generate UI. This means that the windows it generates are definitely not Cocoa windows and will not act like them.

There's not likely to be an easy solution to this issue.

Upvotes: 2

Related Questions