我喜欢黑暗题材。但是,Jupyter笔记本的默认主题是浅色,我找不到更改主题/背景色的选项。这是怎么做到的?


使用Kyle Dunovan的jupyter-themes包很容易做到这一点。您可以使用conda安装它。否则,您将需要使用pip。

使用conda安装:

conda install -c conda-forge jupyterthemes

或小毛病:

pip install jupyterthemes

你可以通过以下方法获得可用主题的列表:

jt -l

所以改变你的主题:

jt -t theme-name

要加载主题,最后,重新加载页面。文档和源代码都在这里。在设置主题时,还可以在同一个命令中指定-T(——toolbar)来保留工具栏,否则工具栏将不会显示。如需帮助,请输入jt -h。

遵循以下步骤

使用pip安装jupyterthemes:

pip install jupyterthemes

然后从下面选择主题,并使用以下命令设置它们。一旦成功安装,我们中的许多人认为我们需要再次启动jupyter服务器,只需刷新页面。

使用以下命令设置主题:

jt -t <theme-name>

可用的主题:

onedork grade3 oceans16 chesterish monokai solarizedl solarizedd

可用主题的截图在其Github存储库中。

在设置主题时,还可以在同一个命令中指定-T(——toolbar)来保留工具栏,否则工具栏将不显示。如需帮助,请输入jt -h。

你可以直接在打开的笔记本上完成:

!pip install jupyterthemes
!jt -t chesterish

重新启动主题应用程序的jupyter服务器

conda install jupyterthemes

在Windows系统中不适合我。我用的是水蟒。

但是,

pip install jupyterthemes

在Anaconda Prompt工作过。

在我改变主题后,它表现得很奇怪。字体很小,看不到工具栏,我真的不喜欢这个新外观。

对于想要还原原有主题的用户,可以按照以下步骤进行操作:

jt -r

您需要在第一次这样做时重新启动Jupyter,之后刷新就足以启用新主题。

或者直接从笔记本里

!jt -r

你可以按照这些步骤来做。

PIP install jupyterthemes或PIP install——upgrade jupyterthemes以升级到最新版本的主题。 然后列出所有的主题:jt -l 在jt-t <themename>之后,例如jt-t solarizedl

使用conda直接安装Jupyterthemes包,使用:

conda install -c conda-forge jupyterthemes

然后,正如其他人指出的那样,使用jt -t <theme-name>更改主题

简单,Jupyter字体大小和内外背景颜色的全局更改(此更改将影响所有笔记本电脑)。

在Windows下,通过运行命令找到config目录: jupyter——config-dir

在Linux中是~/.jupyter

在此目录中创建子文件夹custom 创建文件custom.css并粘贴:

/* Change outer background and make the notebook take all available width */
.container {
    width: 99% !important;
    background: #DDC !important;
}   

/* Change inner background (CODE) */
div.input_area {
    background: #F4F4E2 !important;
    font-size: 16px !important;
}

/* Change global font size (CODE) */
.CodeMirror {
    font-size: 16px !important;
}  

/* Prevent the edit cell highlight box from getting clipped;
 * important so that it also works when cell is in edit mode */
div.cell.selected {
    border-left-width: 1px !important;
} 

最后,重启Jupyter。结果:

而不是在Jupyter内部安装一个库,我建议你使用Chrome中的“黑暗阅读器”扩展(你可以在其他浏览器中找到“黑暗阅读器”扩展,例如Firefox)。 你可以玩它;过滤URL(s)你想有黑暗主题,甚至如何定义黑暗主题为自己。 下面是几个例子:

我希望这能有所帮助。

我的完整解决方案:

1)在chrome上获得黑暗读者,这不仅会让你为Jupyter一个伟大的黑暗主题,而且为每一个你想要的网站(你可以玩不同的过滤器。我使用Dynamic)。

2)将这些代码行粘贴到你的笔记本上,这样图例和轴就可以看到了:

from jupyterthemes import jtplot
jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False)

你已经为迪斯科编码之夜做好了准备!

暗模式:-

我已经使用Raleway字体样式

到C:\User\UserName\.jupyter\custom\custom.css文件

附加给定的样式,这是专门为黑暗模式的jupyter笔记本…

这应该是您当前的custom.css文件:-

/* This file contains any manual css for this page that needs to override the global styles.
    This is only required when different pages style the same element differently. This is just
    a hack to deal with our current css styles and no new styling should be added in this file.*/

#ipython-main-app {
    position: relative;
}

#jupyter-main-app {
    position: relative;
}

现在开始追加内容

.header-bar {
    display: none;
}

#header-container img {
    display: none;
}

#notebook_name {
    margin-left: 0px !important;
}

#header-container {
    padding-left: 0px !important
}

html,
body {
    overflow: hidden;
    font-family: OpenSans;
}

#header {
    background-color: #212121 !important;
    color: #fff;
    padding-top: 20px;
    padding-bottom: 50px;
}

.navbar-collapse {
    background-color: #212121 !important;
    color: #fff;
    border: none !important
}

#menus {
    border: none !important;
    color: white !important;
}

#menus .dropdown-toggle {
    color: white !important;
}

#filelink {
    color: white !important;
    text-align: centerimportant;
    padding-left: 7px;
    text-decoration: none !important;
}

.navbar-default .navbar-nav>.open>a,
.navbar-default .navbar-nav>.open>a:hover,
.navbar-default .navbar-nav>.open>a:focus {
    background-color: #191919 !important;
    color: #eee !important;
    text-align: left !important;
}

.dropdown-menu,
.dropdown-menu a,
.dropdown-submenu a {
    background-color: #191919;
    color: #fff !important;
}

.dropdown-menu>li>a:hover,
.dropdown-menu>li>a:focus,
.dropdown-submenu>a:after {
    background-color: #212121;
    color: #fff !important;
}

.btn-default {
    color: #fff !important;
    background-color: #212121 !important;
    border: none !important;
}

.dropdown {
    text-align: left !important;
}

.form-control.select-xs {
    background-color: #191919 !important;
    color: #eee !important;
    border: none;
    outline: none;
}

#modal_indicator {
    display: none;
}

#kernel_indicator {
    color: #fff;
}

#notification_trusted,
#notification_notebook {
    background-color: #212121;
    color: #eee !important;
    border: none;
    border-bottom: 1px solid #eee;
}

#logout {
    background-color: #191919;
    color: #eee;
}

#maintoolbar-container {
    padding-top: 0px !important;
}

.notebook_app {
    background-color: #222222;
}

::-webkit-scrollbar {
    display: none;
}

#notebook-container {
    background-color: #212121;
}

div.cell.selected,
div.cell.selected.jupyter-soft-selected {
    border: none !important;
}

.cm-keyword {
    color: orange !important;
}

.input_area {
    background-color: #212121 !important;
    color: white !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

.cm-def {
    color: #5bc0de !important;
}

.cm-variable {
    color: yellow !important;
}

.output_subarea.output_text.output_result pre,
.output_subarea.output_text.output_stream.output_stdout pre {
    color: white !important;
}

.CodeMirror-line {
    color: white !important;
}

.cm-operator {
    color: white !important;
}

.cm-number {
    color: lightblue !important;
}

.inner_cell {
    border: 1px thin #eee;
    border-radius: 50px !important;
}

.CodeMirror-lines {
    border-radius: 20px;
}

.prompt.input_prompt {
    color: #5cb85c !important;
}

.prompt.output_prompt {
    color: lightblue;
}

.cm-string {
    color: #6872ac !important;
}

.cm-builtin {
    color: #f0ad4e !important;
}

.run_this_cell {
    color: lightblue !important;
}

.input_area {
    border-radius: 20px;
}

.output_png {
    background-color: white;
}

.CodeMirror-cursor {
    border-left: 1.4px solid white;
}

.box-flex1.output_subarea.raw_input_container {
    color: white;
}

input.raw_input {
    color: black !important;
}

div.output_area pre {
    color: white
}

h1,
h2,
h3,
h4,
h5,
h6 {
    color: white !important;
    font-weight: bolder !important;
}

.CodeMirror-gutter.CodeMirror-linenumber,
.CodeMirror-gutters {
    background-color: #212121 !important;
}


span.filename:hover {
    color: #191919 !important;
    height: auto !important;
}

#site {
    background-color: #191919 !important;
    color: white !important;
}

#tabs li.active a {
    background-color: #212121 !important;
    color: white !important;
}

#tabs li {
    background-color: #191919 !important;
    color: white !important;
    border-top: 1px thin #eee;
}

#notebook_list_header {
    background-color: #212121 !important;
    color: white !important;
}

#running .panel-group .panel {
    background-color: #212121 !important;
    color: white !important;
}

#accordion.panel-heading {
    background-color: #212121 !important;
}

#running .panel-group .panel .panel-heading {
    background-color: #212121;
    color: white
}

.item_name {
    color: white !important;
    cursor: pointer !important;
}

.list_item:hover {
    background-color: #212121 !important;
}

.item_icon.icon-fixed-width {
    color: white !important;
}

#texteditor-backdrop {
    background-color: #191919 !important;
    border-top: 1px solid #eee;
}

.CodeMirror {
    background-color: #212121 !important;
}

#texteditor-backdrop #texteditor-container .CodeMirror-gutter,
#texteditor-backdrop #texteditor-container .CodeMirror-gutters {
    background-color: #212121 !important;
}

.celltoolbar {
    background-color: #212121 !important;
    border: none !important;
}

如果有人有兴趣在启用主题的docker中运行anaconda

docker run -t --rm -p 8888:8888 -v $(pwd):/opt/notebooks continuumio/anaconda3 /bin/bash -c "pip install jupyterthemes; jt -t onedork; /opt/conda/bin/jupyter notebook --ip=0.0.0.0 --port=8888 --notebook-dir=/opt/notebooks --allow-root --no-browser;"

您可以使用运行笔记本中的set_nb_theme更改主题

!pip install jupyterthemes

from jupyterthemes import get_themes
import jupyterthemes as jt
from jupyterthemes.stylefx import set_nb_theme

set_nb_theme('chesterish')

从https://www.kaggle.com/getting-started/97540粘贴

使用FireFox插件“暗黑木星”。

!pip install jupyterthemes

运行这个库:

from jupyterthemes import get_themes
import jupyterthemes as jt
from jupyterthemes.stylefx import set_nb_theme

这:

set_nb_theme('monokai')

主题:

’monokai’, ’chesterish’, ’oceans16’, ’solarizedl’, ’solarizedd’, ’grade3’, ’onedork’

如前所述,您可以安装使用更广泛的jupyterthemes。 但是,我也可以更喜欢和推荐jupyter-themer,它更容易使用,不影响jupyter笔记本的默认形状。

安装:pip install jupyter-themer

带有文档和示例的存储库(*目前,示例存储在未合并的pull-request中):@github: jupyter-thamer

我最喜欢的定制:jupyter-themer -b dark -c zenburn。

另一个选择是如果你使用谷歌chrome,想要一个黑暗的主题,让你在jupyter/网页上工作几个小时更容易,同时也让你的代码中的配色方案可读,那就是在实验中使用“Web内容的自动暗模式”标志- chrome://flags -我通常会选择“启用选择性图像反转”选项。

如果在尝试使用PIP时出现错误,您可以使用CMD并运行您的命令。