the.real.gruycho
the.real.gruycho

Reputation: 744

interactive mode doesn't switch on from script (matplotlib 1.4.0 python 2.7.5 on mac osx 10.8.5)

Using python 2.6 on my mac the following works fine (i.e. a plot window opens):

import matplotlib.pyplot as plt
from numpy import linspace, sin, pi
plt.ion()
print "Is interactive:?", plt.isinteractive()

x = linspace(-pi, pi, 1001)
plt.plot(x, sin(x))

raw_input() #keep the window open

It works when I run it in shell (i.e. $ python test.py) as well as when I run it in an interactive python terminal.

I recently installed python 2.7 and with it nothing happens (more precisely, plot window appears in Dock, but doesn't open) when I run my script from shell. The value of plt.isinteractive() is false even after plt.ion().

When I run the same code in an interactive python terminal, everything is fine.

The answer to this question makes the plot window appear, but I find it annoying that now I have to add plt.pause(0.1) to my script.

Is there a way to get the earlier behaviour without modifying the code?

The backend is macosx.

Upvotes: 0

Views: 891

Answers (1)

the.real.gruycho
the.real.gruycho

Reputation: 744

It seems that this is a bug related to matplotlib 1.4. An ugly workaround is to include:

import sys
sys.ps1 = 'SOMETHING'

before importing matplotlib.

Alternatively, one can use ipython to run the script.

For more details see here https://github.com/matplotlib/matplotlib/issues/3505

Upvotes: 1

Related Questions