IPython自动打开matplotlib交互模式 [英] IPython automatically turning on matplotlib interactive mode

查看:77
本文介绍了IPython自动打开matplotlib交互模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在经历来自IPython的一些新奇的行为.我只需要重新安装miniconda,就可以拥有新的IPython和Matplotlib版本.事实证明,IPython会自动将matplotlib切换到交互模式(这具有使我保存的图形在脚本中为空的烦人的副作用,因为在关闭窗口后它们会保存).

I'm experiencing some newly odd behavior from IPython. I just had to do a clean reinstall of my miniconda, so I now have fresh IPython and Matplotlib versions. It turns out that IPython is automatically switching matplotlib to interactive mode (which has the annoying side effect of making my saved figures blank in my scripts, because they save after I close the window).

这是一个例子:

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

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

Is there a way to stop this behavior?

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

Note, I've tested the same code in regular python and interactive mode stays off.

推荐答案

这是matplotlib和IPython之间相互作用的一个错误,该问题已在matplotlib版本3.1.0中引入(通过#14979 ).

It's a bug in the interplay between matplotlib and IPython, which got introduced in matplotlib version 3.1.0 (via #12637). It will be fixed in matplotlib 3.2 (via #14979).

您拥有的选项:

这篇关于IPython自动打开matplotlib交互模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆