LoginSignup
3
4

More than 5 years have passed since last update.

Jupyter NotebookのNbextensionsで邪魔なscratchpadのサイズを変更する

Last updated at Posted at 2018-07-19

Jupyter Notebookの機能を拡張する、NbextensionのScratchpadが邪魔

標準の見た目
image.png
↑をこう↓する
image.png

変更手順

簡単なバージョン:jupyterのコード中で変更する

image.png

セル中でHTMLを指定し、実行するだけで↑の図のようになる。

任意のCodeセル.ipynb
%%HTML
<style>
/* コード記載部の位置と幅と背景色変更 */
#notebook-container {
    /* 左寄せにする。Contentsの表示など使わないなら0でもよい */
    margin-left:40ex;
    /* 幅を指定 40%くらいでもよいけど、お好みで。 */
    width: 105ex;
    /* 背景色 */
    background-color:#d0d0d8;
}

/* scratchpadの幅と背景色の変更 */                                 
#nbextension-scratchpad { width: 80ex; background-color: #d0d0df; }

/* 以下おまけ */
/* 背景の色 */
body.notebook_app{ background-color:#a0a0a8; }
/* ヘッダーの色 */
#header { background-color:#d0d0d8; }
/* 実行番号 In [] 部分の幅 */
.prompt.input_prompt { min-width: 11ex; }
/* マークダウンのセルの背景 */
.text_cell_render.rendered_html { background-color:#f0f0f8; }

</style>

手間のかかるバージョン:いちいち設定したくない方向け(Windows)

コード記載部分の設定

C:\Users\ユーザー名\.jupyter\custom\ の「custom.css」を編集

custom.css
/* コード記載部の位置と幅と背景色変更 */
#notebook-container {
    /* 左寄せにする。Contentsの表示など使わないなら0でもよい */
    margin-left:40ex;
    /* 幅を指定 40%くらいでもよいけど、お好みで。 */
    width: 105ex;
    /* 背景色 */
    background-color:#d0d0d8;
}

/* scratchpadの幅と背景色の変更 */                                 
#nbextension-scratchpad { width: 90ex; background-color: #d0d0df; }

/* 以下おまけ */
/* 背景の色 */
body.notebook_app{ background-color:#a0a0a8; }
/* ヘッダーの色 */
#header { background-color:#d0d0d8; }
/* 実行番号 In [] 部分の幅 */
.prompt.input_prompt { min-width: 11ex; }
/* マークダウンのセルの背景 */
.text_cell_render.rendered_html { background-color:#f0f0f8; }

/* これ以降は変更しない */

Nbextensionsの設定

Anaconda Promptなど、pythonを実行できる環境で、下記を実行

jupyter contrib nbextension install --user

(詳細は、
https://github.com/ipython-contrib/jupyter_contrib_nbextensions
の「2. Install javascript and css files」を参照してください)

すると、C:\Users\ユーザー名\AppData\Roaming\jupyter\nbextensions\scratchpad\ など
Nbextensionsの一連の機能に関するフォルダが作られるので、scratchpadフォルダの「scratchpad.css」を開いて「#nbextension-scratchpad」の部分を編集する。

scratchpad.css
#nbextension-scratchpad {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 90ex; /* 標準は50% */
  background-color: #d0d0df; /* 標準は #F8F5E1; */
  border-left: 1px solid #aaa;
  border-top: 1px solid #aaa;
  z-index: 105;
}

★おススメ:スクラッチパッドの高さを変えたい人は、「main.js」も編集する
height: site_height の部分。
*0.7くらいあると、スクラッチパッドの上部にスペースがあいて、
ブラウザを狭く使ってコードとスクラッチパッドが重なってもコードが見える。

main.js
//85行目以降に、スクラッチパッドを開いた時の高さの定義があるので、site_hight*0.7くらいで高さを調整
  Scratchpad.prototype.expand = function () {
    this.collapsed = false;
    var site_height = $("#site").height();
    this.element.animate({
      height: site_height*0.7,
    }, 200);

参考

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4