Nate
Nate

Reputation: 1948

Cannot manually close matplotlib plot window

I'm running Python v2.7 and matplotlib v1.5.0 on Mac OS X Yosemite. Up to recently, I was able to run my script in the interactive interpreter, show a plot, and then manually kill the window. For example

import numpy as np
x = np.arange(1,10)
y = np.arange(1,10)
plt.plot(x,y)
plt.show()

This used to work fine. The window would close and I'd return to the prompt. However, now when I hit the red X to close the window, the window remains open. My command prompt returns and works fine, but the window is stuck and I see the spinning beach ball over it.

enter image description here

(Note that the cursor doesn't appear in the image, but you can see the red X is greyed out because I've hit close but it is stuck open).

It's not until I run the script a second time that the first window closes, but then I'm stuck with a second open plot with the same problem. I'm a bit confused because this only happened recently. Up till now, the window would close fine.

It's not a huge issue, because Python still runs and I can still make new plots, but I'm curious as to why the window would all of a sudden stick open. Any advice?

UPDATE

I solved the problem by switching the interactive backend. Either Qt4Agg or TkAgg as an interactive backend resolves the issue. But the question remains why the macosx and CocoaAgg backends show this behavior.

Upvotes: 11

Views: 6380

Answers (2)

mattsilver
mattsilver

Reputation: 4396

For a permanent solution (I'd rather not have to switch backends every time I open ipython) you can modify matplotlibrc.

There are various matplotlibrc files that can be changed (i.e. for just a local directory, or globally, etc.). To find the configuration file that's been loaded for your ipython session, use matplotlib.matplotlib_fname(). Here's what I got:

In [1]: import matplotlib

In [2]: matplotlib.matplotlib_fname()
Out[2]: u'/usr/local/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'

Opening the rc file and changing the line:

backend      : macosx

to read:

backend      : Qt4Agg

did the trick for me.

Upvotes: 9

Nate
Nate

Reputation: 1948

I solved the problem by switching the interactive backend. Either Qt4Agg or TkAgg as an interactive backend resolves the issue.

Upvotes: 5

Related Questions