python - IPython自动开启matplotlib交互模式

标签 python matplotlib ipython conda miniconda

我遇到了一些来自 IPython 的奇怪行为。我只需要干净地重新安装我的 miniconda,所以我现在有了新的 IPython 和 Matplotlib 版本。事实证明,IPython 会自动将 matplotlib 切换到交互模式(这有一个烦人的副作用,就是让我保存的图形在我的脚本中变成空白,因为它们是在我关闭窗口后保存的)。

这是一个例子:

Python 3.7.3 | packaged by conda-forge | (default, Jul  1 2019, 21:52:21) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.6.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import matplotlib as mpl                                                                                                                              

In [2]: import matplotlib.pyplot as plt                                                                                                                       

In [3]: mpl.is_interactive()                                                                                                                                  
Out[3]: False

In [4]: plt.plot([1,2])                                                                                                                                       
Out[4]: [<matplotlib.lines.Line2D at 0x7f0b0b048940>]

In [5]: mpl.is_interactive()                                                                                                                                  
Out[5]: True

有没有办法阻止这种行为?

请注意,我已经在常规 python 中测试了相同的代码,并且交互模式保持关闭。

最佳答案

这是 matplotlib 和 IPython 之间相互作用的一个错误,它在 matplotlib 版本 3.1.0 中引入(通过 #12637 )。它将在 matplotlib 3.2 中修复(通过 #14979 )。

您有以下选择:

关于python - IPython自动开启matplotlib交互模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57153840/

相关文章:

python - matplotlib 在空白处写入文本

ipython - 在单独的命名空间中执行另一个 ipython notebook

Python min、max、mean、median 代码函数定义误差

python - 如何在 Django View 装饰器的上下文中设置值?

python - plt.subplot 轴共享不起作用

python - 使用 fill_ Between 函数绘制直线拟合中的不确定性 : "The truth value of an array with more than one element is ambiguous."

python - Django 完整性错误处理

python - 如何在 sqlite 中执行带有占位符的 SELECT * LIKE 语句?

python - Jupyter 中的调试和运行模式

python - IPython Jupyter Notebook Latex 新页面