如何设置关键字“阻止"?在plt.show()默认等于True吗? [英] How does one set keyword "block" in plt.show() equal to True by default?
问题描述
出于某种原因,我需要明确地将关键字block"设置为等于 True,以便在我从 bash shell 运行脚本时显示图.(当我从ipython shell运行它时,不需要它).几乎每个人似乎都知道该如何将其默认设置为True?
For some reason, I need to set the keyword "block" equal to True explicitly, so that plots are shown when I run a script from the bash shell. (I don't need that when I run it from the ipython shell). How can I set that argument to True by default as nearly everyone seems to have it?
示例:
import matplotlib.pyplot as plt
plt.plot([1,2,3], [1,2,3])
plt.show(block=True)
即使该参数未明确设置为 True,我也希望显示图,即:
I would like plots to show up even if that argument isn't set to True explicitly, that is:
import matplotlib.pyplot as plt
plt.plot([1,2,3], [1,2,3])
plt.show()
我的 matplotlibrc 包含:
My matplotlibrc contains:
后端:MacOSX
交互式:True
工具栏:toolbar2
时区:UTC
toolbar : toolbar2
timezone : UTC
推荐答案
mpl的交互"模式确定 plt.show
的行为.如果处于交互"模式,则假定还有其他东西来管理GUI事件循环.使用
The 'interactive' mode of mpl determines the behavior of plt.show
. If in 'interactive' mode, it assumes that there is something else managing the GUI event loop. When running a script with
python -i script.py
将使您进入交互式外壳.坐在REPL中时,python REPL循环和GUI事件循环之间存在集成,这使得GUI循环可以在后台运行,从而使图形具有交互性".如果在这种情况下,互动"模式为 not ,则在关闭图形之前,您不会得到提示.
will drop you into an interactive shell. When siting in the REPL, there is integration between the python REPL loop and the GUI event loop which allows the GUI loop to run in the background, which makes the figure 'interactive'. If 'interactive' mode was not on in this case, you would not get the prompt until you have closed the figure.
'interactive' 模式可以通过调用 plt.ion()
或通过设置 matplotlibrc
中的 'interactive'
键来启用.
'interactive' mode can be enabled either by calling plt.ion()
or by setting the 'interactive'
key in matplotlibrc
.
我强烈建议您将rcparam值保留为 False
.
I strongly suggest that you leave the rcparam value to be False
.
这篇关于如何设置关键字“阻止"?在plt.show()默认等于True吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!