【22】Jupyter Notebook 自定义外观

Jupyter Notebook 原生的外观可以说是能用但是绝对不好看。所以可以试试修改 css 获得一个好看一些的外观。

Windows 系统下,在个人文件夹 C:\Users\****\ 下找到或者新建文件夹 .jupyter。或者在 CMD / PowerShell 键入:

1
jupyter notebook --generate-config

然后就会生成这个文件夹。在 .jupyter 文件夹下新建一个文件夹叫做 custom,然后新建文件 custom.css。参考内容:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* Ref: https://www.zhihu.com/question/40012144 */

/* Body */
/* #notebook-container {
    width: 90%
} */

/* Markdown */
div#notebook {
    font-family: "Microsoft YaHei";
    line-height: 20px;
    -webkit-font-smoothing: antialiased !important;
}

/* Markdown - h2 */
div#notebook h2 {
    color: #007aff;
}

/* Markdown - quote */
div#notebook blockquote{
    background-color: #f8f8f8;
    color: #505050;
    padding: 8.5px;
    margin: 0.5em -0.5em 0.5em -0.4em;
}

/* Markdown - code in paragraph */
div#notebook p code, div#notebook li code {
    font-family: "Consolas", "Microsoft YaHei";
    font-size: 1em !important;
    color: #111111;
    border: 0.5px solid #cfcfcf;
    border-radius: 2px;
    background-color: #f7f7f7;
    padding: .1em .2em;
    margin: 0px 2px;
}

/* Markdown - code */
div.text_cell_render pre {
    border: 1px solid #cfcfcf;
    border-radius: 2px;
    background: #f7f7f7;
    line-height: 1.21429em;
    padding: 8.5px;
    margin: 0.5em -0.5em 0.5em -0.4em;
}
div.text_cell_render code {
    background: #f7f7f7;
}

/* Code */
div.CodeMirror pre {
    font-family: "Consolas";
    font-size: 11pt;
    line-height: 140%;
    -webkit-font-smoothing: antialiased !important;
}

/* Code - output */
div.output pre {
    font-family: "Microsoft YaHei";
    line-height: 20px;
    -webkit-font-smoothing: antialiased !important;
}

/* Code - comment */
span.cm-comment {
    font-family: "Microsoft YaHei" !important;
    font-style: italic !important;
}

/* Promts (In and Out) */
div.prompt {
    font-family: "Consolas";
    font-size: 10pt;
}

/* Line numbers */
div.CodeMirror-linenumber {
    font-family: 'Microsoft YaHei';
}


/* Code - highlighting */
.cm-s-ipython .CodeMirror-cursor {
    border-left: 1px solid #ff711a !important;
}
.cm-s-ipython span.cm-comment {
    color: #8d8d8d;
    font-style: italic;
}
.cm-s-ipython span.cm-atom {
    color: #055be0;
}
.cm-s-ipython span.cm-number {
    color: #ff8132;
}
.cm-s-ipython span.cm-property {
    color: #303030;
}
.cm-s-ipython span.cm-attribute {
    color: #303030;
}
.cm-s-ipython span.cm-keyword {
    color: #713bc5;
    font-weight: bold;
}
.cm-s-ipython span.cm-string {
    color: #009e07;
}
.cm-s-ipython span.cm-meta {
    color: #aa22ff;
}
.cm-s-ipython span.cm-operator {
    color: #055be0;
}
.cm-s-ipython span.cm-builtin {
    color: #e22978;
}
.cm-s-ipython span.cm-variable {
    color: #303030;
}
.cm-s-ipython span.cm-variable-2 {
    color: #de143d;
}
.cm-s-ipython span.cm-variable-3 {
    color: #aa22ff;
}
.cm-s-ipython span.cm-def {
    color: #e22978;
    font-weight: bold;
}
.cm-s-ipython span.cm-error {
    background: rgba(191, 97, 106, .40);
}
.cm-s-ipython span.cm-tag {
    color: #e22978;
}
.cm-s-ipython span.cm-link {
    color: #ff8132;
}
.cm-s-ipython span.cm-storage {
    color: #055be0;
}
.cm-s-ipython span.cm-entity {
    color: #e22978;
}
.cm-s-ipython span.cm-quote {
    color: #009e07;
}
div.CodeMirror span.CodeMirror-matchingbracket {
    color: #1c1c1c;
    background-color: rgba(30, 112, 199, .30);
}
div.CodeMirror span.CodeMirror-nonmatchingbracket {
    color: #1c1c1c;
    background: rgba(191, 97, 106, .40) !important;
}
.cm-s-default .cm-hr {
    color: #055be0;
}

参考: https://www.zhihu.com/question/40012144

然后 Jupyter 就会变得好看了。


本文阅读量
本站访客量