【问题标题】:interactive mode doesn't switch on from script (matplotlib 1.4.0 python 2.7.5 on mac osx 10.8.5)交互模式不会从脚本打开(mac osx 10.8.5 上的 matplotlib 1.4.0 python 2.7.5)
【发布时间】: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


    【解决方案1】:

    这似乎是一个与 matplotlib 1.4 相关的bug。一个丑陋的解决方法是包括:

    import sys
    sys.ps1 = 'SOMETHING'
    

    在导入 matplotlib 之前。

    或者,可以使用 ipython 来运行脚本。

    更多详情请看这里https://github.com/matplotlib/matplotlib/issues/3505

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-15
      • 2016-05-29
      • 2017-08-26
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多