Ipython Notebook:默认初始化Python代码 [英] Ipython Notebook: Default Initialization Python Code

查看:126
本文介绍了Ipython Notebook:默认初始化Python代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将iPython Notebook用于科学应用,并且我总是在绘制实验数据集. iPython Notebook和Matplotlib结合使用时的默认图像渲染和颜色循环行为非常糟糕,但在进行以下调整后效果很好.

I use iPython Notebook for scientific applications and I'm always plotting experimental data sets. The default image rendering and color cycling behavior of the combination of iPython Notebook and Matplotlib is pretty bad, but it's great after the following tweaks.

# ipython notebook specific
%pylab inline

# imports
from matplotlib import pyplot as plt
import matplotlib as mpl
from seaborn.apionly import set_palette
from IPython.display import set_matplotlib_formats

# configure plotting
set_matplotlib_formats('pdf', 'svg')
set_palette('Set1', n_colors=15, desat=None)
mpl.rcParams['figure.figsize']=(12.0,2.0)

我不想在每个笔记本中都手动输入这些内容.我该如何对将要创建的所有笔记本执行这些操作?

I don't want to have to enter these manually in every notebook. How can I have these executed for all notebooks I'll ever create?

推荐答案

您可以在$ HOME/.ipython/profile_default/startup/中创建包含要在启动时执行的代码的Python文件.

You can create Python files in $HOME/.ipython/profile_default/startup/ that contains the code you want executed at startup.

例如,您可以创建$ HOME/.ipython/profile_default/startup/00-init.py:

For example, you can create $HOME/.ipython/profile_default/startup/00-init.py:

# imports
from matplotlib import pyplot as plt
import matplotlib as mpl
from seaborn.apionly import set_palette
from IPython.display import set_matplotlib_formats

# configure plotting
set_matplotlib_formats('pdf', 'svg')
set_palette('Set1', n_colors=15, desat=None)
mpl.rcParams['figure.figsize']=(12.0,2.0)

请注意,此处不支持IPython魔术,因此%matplotlib内联将不起作用. 此问题涉及将%matplotlib设置为默认内联.

Note that IPython magics are not supported here, so %matplotlib inline won't work. This question deals with making %matplotlib inline the default.

您应该注意,如果您更改IPython环境的默认值,则笔记本可能无法在其他人的IPython安装上运行.

You should be aware that if you change the defaults for your IPython environment, your notebooks may not work on other people's IPython installations.

这篇关于Ipython Notebook:默认初始化Python代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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