Python matplotlib:plt.isinteractive()在终端中运行脚本时,在调用plt.ion()后返回0而不是True或False?

Python matplotlib:plt.isinteractive()在终端中运行脚本时,在调用plt.ion()后返回0而不是True或False?,python,matplotlib,pycharm,gnome-terminal,Python,Matplotlib,Pycharm,Gnome Terminal,这是我的剧本: from __future__ import division import numpy as np import matplotlib print "matplotlib backend: {}".format(matplotlib.get_backend()) from matplotlib import pyplot as plt import sys print "-----------------------" print "Is matplotlib plott

这是我的剧本:

from __future__ import division
import numpy as np

import matplotlib
print "matplotlib backend: {}".format(matplotlib.get_backend())

from matplotlib import pyplot as plt
import sys

print "-----------------------"
print "Is matplotlib plotting interactive? {}".format(plt.isinteractive())

if not plt.isinteractive():
    print "matplotlib plotting is not interactive..."
    print "Trying to set matplotlib plotting to be interactive..."
    plt.ion()

print "-----------------------"
print "Is matplotlib plotting interactive now? {}".format(plt.isinteractive())

continue_script = raw_input("Should script continue? [y/[n]]")
if continue_script.strip() != "y":
    sys.exit(0)

plt.draw()

continue_script = raw_input("Should script continue? [y/[n]]")
if continue_script.strip() != "y":
    sys.exit(0)
令人惊讶的是,当在终端中运行脚本时(
python interactive_plotting.py
——最好是在PyCharm中运行它[因此使用PyCharm标记],但我在那里遇到了同样的问题,所以我现在只是在普通的
gnome终端中尝试),我看到了以下输出:

matplotlib backend: Qt4Agg
-----------------------
Is matplotlib plotting interactive? False
matplotlib plotting is not interactive...
Trying to set matplotlib plotting to be interactive...
-----------------------
Is matplotlib plotting interactive now? 0
-----------------------
Should script continue? [y/[n]]n #(I supply n as the response)
请注意
Qt4Agg
。现在,如果我继续脚本,那么后续的
plt.draw()
命令不会导致图形弹出

如果我打开一个Python终端并尝试一下,一切似乎都正常:

Python 2.7.9 |Anaconda 2.1.0 (64-bit)| (default, Mar  9 2015, 16:20:48) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> from matplotlib import pyplot as plt
>>> plt.isinteractive()
False
>>> plt.ion()
>>> plt.isinteractive()
True
>>> 
随后运行
plt.draw()
命令会导致弹出一个空图形,我可以在终端中键入其他命令,并查看动态更新的图形。如果我不是在Python解释器中运行脚本,这正是我想要的

发生了什么事,我怎样才能让事情顺利进行