0

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.

asked Sep 21, 2014 at 14:03

1 Answer 1

1

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

answered Sep 21, 2014 at 18:39

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.