小编典典

在IPython Notebook中自动内联运行%matplotlib

python

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

%matplotlib inline

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


阅读 208

收藏
2020-12-20

共1个答案

小编典典

配置方式

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

不鼓励使用%pylabinline进行绘图。

它将各种不需要的杂项引入您的名称空间。

%matplotlib另一方面,无需插入名称空间即可启用内联绘图。您需要进行显式调用才能导入matplotlib和numpy。

import matplotlib.pyplot as plt
import numpy as np

现在,您已经拥有可复制的代码,因此可以完全克服显式输入导入的低价格。

2020-12-20