python - 在 IPython Notebook 中自动运行 %matplotlib inline

标签 python matplotlib ipython-notebook

每次我启动 IPython Notebook 时,我运行的第一个命令是

%matplotlib inline

有什么方法可以更改我的配置文件,以便在我启动 IPython 时,它会自动处于此模式?

最佳答案

配置方式

IPython 有配置文件,位于 ~/.ipython/profile_*。默认配置文件称为 profile_default。在这个文件夹中有两个主要的配置文件:

  • ipython_config.py
  • ipython_kernel_config.py

将matplotlib的内联选项添加到ipython_kernel_config.py:

c = get_config()
# ... Any other configurables you want to set
c.InteractiveShellApp.matplotlib = "inline"

matplotlib 与 pylab

使用 %pylab 来获得内联绘图是 discouraged .

它在你的命名空间中引入了你不需要的各种垃圾。

%matplotlib 另一方面,可以在不注入(inject)命名空间的情况下进行内联绘图。您需要进行显式调用才能导入 matplotlib 和 numpy。

import matplotlib.pyplot as plt
import numpy as np

您现在拥有可重现的代码这一事实完全可以克服显式输入导入的小成本。

关于python - 在 IPython Notebook 中自动运行 %matplotlib inline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21176731/

相关文章:

python - pandas Series (pandas.Series.query()) 是否有查询方法或类似方法?

python - 使用 xlrd 时读取包含公式的单元格值返回 0.0

python - Python 中新旧三元条件运算符的不同结果

python - 自定义蜘蛛图 --> 在 matplotlib 中显示极坐标图上点之间的曲线而不是直线

python - IPython 笔记本从原始文本单元格读取字符串

python - 解决 Safari 中 Webdriver 缺乏交互 API 的问题

python - matplotlib 中两个定义函数之间的区域孵化

python - 在 matplotlib 中修剪 3d 图之外的数据

python - 无法从 anaconda 启动 ipython notebook

r - 使用 Jupyter Notebook 的 R Notebook 中的内核错误