Jupyter Notebook配置

Jupyter 大法好!

TOC

Jupyter Notebook配置

插件

Install

  • by conda
1
conda install -c conda-forge jupyter_contrib_nbextensions
2
conda install -c conda-forge jupyter_nbextensions_configurator
  • by pip
1
pip install jupyter_nbextensions_configurator jupyter_contrib_nbextensions
2
jupyter contrib nbextension install --user
3
jupyter nbextensions_configurator enable --user

挑几个重点安利

  • Variable Inspector: 变量监视器
    建议勾选Display window at startup
  • Live Markdown Preview
    建议勾选Parameters里的右侧预览
  • Table of Contents(2)
    同建议勾选自启
  • Codefolding in Editor: 缩进折叠

页面格式定制(CSS)

  • 临时
1
from IPython.core.display import display, HTML
2
display(HTML('''<style>
3
.container { 
4
    width:80% !important; 
5
    margin-left:0 !important;
6
}
7
div.prompt_container{
8
    width: 76px;
9
}
10
div.cell.code_cell.input_prompt{
11
    text-align: left !important;
12
}
13
.cm-s-ipython .CodeMirror-gutters{
14
    width: 27px !important;
15
}
16
</style>'''))
  • 长久之计

创建文件~/.jupyter/custom/custom.css

1
.container {
2
    width: 80% !important;      // 宽度
3
    margin-left: 0 !important;  // 居左
4
}
5
div.prompt_container{
6
    width: 76px;
7
}
8
div.cell.code_cell.input_prompt{
9
    text-align: left !important;
10
}
11
.cm-s-ipython .CodeMirror-gutters{
12
    width: 27px !important;
13
}

reference: https://stackoverflow.com/questions/21971449/how-do-i-increase-the-cell-width-of-the-jupyter-ipython-notebook-in-my-browser

更换主题/字体

Install

没想到两者要install的库名居然差了个-

主题

配置主题and字体

jt -f inconsolata -t chesterish -T
  • -f inconsolata: 使用inconsolata等宽字体
  • -t chesterish: 选择chesterish主题
  • -T: 同时打开顶部的工具栏(Toolbar)
  • -N: 显示笔记本的名字(Name)(我觉得这个鸡肋,还占用了一行空间,不如省去)

暗色 theme 的 plot 加成

1
from jupyterthemes import jtplot
2
jtplot.style(theme='chesterish', context='notebook', ticks=True)#, grid=False)

Hotkey

key key-name key-character
command cmd
option alt
control ctrl
enter Enter
shift Shift

组合键用-连接

画图

常见可用

1
%pylab
2
%matplotlib qt5

配置文件

生成配置文件

1
jupyter notebook --generate-config

阅读Markdown

安装notedown插件

1
pip install https://github.com/mli/notedown/tarball/master

运行

  • 方法一: 每次都加命令
1
jupyter notebook --NotebookApp.contents_manager_class='notedown.NotedownContentsManager'
  • 方法二: 修改配置文件

添加

1
c.NotebookApp.contents_manager_class = 'notedown.NotedownContentsManager'

然后正常运行即可


reference: