【发布时间】:2016-08-17 11:00:29
【问题描述】:
由于某种原因,在 ipython3 / ipython 中运行以下代码时,我无法绘图。窗口会弹出,但会保持灰色。
$ ipython
import matplotlib
matplotlib.get_backend()
# TKAgg
plt.plot(range(10))
plt.show()
# this works!
# Close the window with alt+f4 to get the command line back
plt.ion()
plt.plot(range(10))
# this doesn't work and the plot window freezes (not the terminal)
# Close the frozen window
plt.close()
为了解决这个问题,我改为运行以下命令:
ipython --pylab
现在上面的所有代码都可以工作了,所以我开始寻找一种自动加载的方法。所以我查看了我的默认 ipython 配置文件配置文件 (~/.ipython/profile_default/ipython_config.py),在搜索 matplotlib 时发现了两个代码块:
# Pre-load matplotlib and numpy for interactive use, selecting a particular
# matplotlib backend and loop integration.
# c.InteractiveShellApp.pylab = None
和
# Pre-load matplotlib and numpy for interactive use, selecting a particular
# matplotlib backend and loop integration.
# c.TerminalIPythonApp.pylab = None
所以我取消了 c.IntractiveShellApp.pylab 的注释并将其设置为 'auto' 并且一切正常,但我不确定我应该更改两个参数中的哪一个以及有什么区别!
【问题讨论】:
标签: matplotlib ipython