【发布时间】:2014-11-15 14:06:48
【问题描述】:
在我的 mac 上使用 python 2.6 可以正常工作(即打开一个绘图窗口):
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
当我在 shell(即 $ python test.py)中运行它以及在交互式 python 终端中运行它时,它都可以工作。
我最近安装了 python 2.7,当我从 shell 运行脚本时,没有任何反应(更准确地说,绘图窗口出现在 Dock 中,但没有打开)。 plt.isinteractive() 的值即使在 plt.ion() 之后也是 false。
当我在交互式 python 终端中运行相同的代码时,一切都很好。
this question 的答案使绘图窗口出现,但我发现现在我必须将 plt.pause(0.1) 添加到我的脚本中。
有没有办法在不修改代码的情况下获得早期的行为?
后端是macosx。
【问题讨论】:
标签: macos python-2.7 matplotlib