如何在Jupyter Notebook中更改主题?

Mob*_*han 127 themes editor jupyter-notebook

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

Aar*_*ron 179

使用jupyter-themesKyle Dunovan 的包装很容易做到.您可以使用它来安装它conda.否则,您将需要使用pip.

用conda安装:

conda install jupyterthemes
Run Code Online (Sandbox Code Playgroud)

或者

pip install jupyterthemes
Run Code Online (Sandbox Code Playgroud)

然后改变你的主题

jt -t chesterish
Run Code Online (Sandbox Code Playgroud)

加载chesterish主题或任何其他.最后,重新加载页面.文档和源代码在这里:https://github.com/dunovank/jupyter-themes

  • 注意 - 我必须重新启动jupyter服务器才能工作. (14认同)
  • 如果 `jupyterthemes` 在 conda-forge 上,答案应该是说需要 `conda install jupyterthemes -c conda-forge` 或者放弃建议使用 conda 安装。 (13认同)
  • 在添加conda-forge通道`conda config --add channels conda-forge`后,我确实成功了conda (7认同)
  • 第一次****可能需要重新启动`jupyter notebook`才能工作,但下次只需在终端上更改`jt -t <themes>`并重新加载笔记本页面.它对我来说就像这样. (6认同)
  • 如何重置为默认主题? (4认同)
  • “ jupyterthemes”既不在conda上,也不在conda-forge上,安装它的唯一方法是仅通过“ pip” (3认同)
  • 这个库“jupyterthemes”有大量的依赖项。仅仅改变主题颜色似乎太过分了,还有其他选择吗? (3认同)
  • 可以注意到,`jt -r`可以将主题重置为默认,并且无需重新启动服务器,只需刷新 Jupiter URL 即可。 (3认同)

Sah*_*pal 51

跟着这些步骤:-

点子安装主题.

pip install jupyterthemes
Run Code Online (Sandbox Code Playgroud)

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

jt -t <theme-name>
Run Code Online (Sandbox Code Playgroud)

主题名称列表

onedork | 3级| oceans16 | chesterish | monokai | solarizedl | solarizedd

  • 这并不能保证一个新的答案.只是对现有的一个小修改. (5认同)
  • [this]也有一个Chrome扩展程序(https://chrome.google.com/webstore/detail/jupyter-notebook-themes/aenokjighnnjpgdifpjeoebjdaehmkkn?hl=zh-CN)。它基本上做同样的事情,但是没有终端交互。 (3认同)
  • 为了完整起见,除了列出的主题之外,这2个选项也可用:截至2019年1月的gruvboxd,gruvboxl (3认同)
  • 经典主题的名字是什么?如果我想恢复并回到最初的经典? (2认同)
  • 如果在安装“jupyterthemes”之前运行“jupyter”,刷新页面以加载新主题将不起作用。这种情况,只需重启服务器,然后刷新页面即可。 (2认同)

Ami*_*r F 24

您可以直接从打开的笔记本中执行此操作:

!pip install jupyterthemes
!jt -t chesterish
Run Code Online (Sandbox Code Playgroud)


Nat*_*bsi 24

我改变主题后表现得很奇怪.字体很小,看不到工具栏,我真的不喜欢新的样子.

对于那些想要恢复原始主题的人,可以按如下方式进行:

jt -r
Run Code Online (Sandbox Code Playgroud)

您需要在第一次执行时重新启动Jupyter,稍后刷新就足以启用新主题.

或直接从笔记本内部

!jt -r
Run Code Online (Sandbox Code Playgroud)


Woj*_*ski 20

!pip install jupyterthemes
Run Code Online (Sandbox Code Playgroud)

运行这个库:

!pip install jupyterthemes
Run Code Online (Sandbox Code Playgroud)

和这个:

set_nb_theme('monokai')
Run Code Online (Sandbox Code Playgroud)

主题:

'monokai'、'chesterish'、'oceans16'、'solarizedl'、'solarized'、'grade3'、'onedork'


raf*_*pek 13

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;
} 
Run Code Online (Sandbox Code Playgroud)

最后 - 重新启动 Jupyter。结果:

较暗的背景

  • 对于那些想要完成粘贴 css 文件的人(像我一样);(不是我的!)我尝试了这个,它完美无缺 https://raw.githubusercontent.com/powerpak/jupyter-dark-theme/master/custom.css (3认同)
  • 请问,如何撤销? (2认同)
  • 删除您创建的文件 (custom.css) 并重新启动 Jupyter。 (2认同)

Beh*_*hti 11

相反,安装内Jupyter库的,我会建议你使用'暗读者扩展- https://chrome.google.com/webstore/detail/dark-reader/eimadpbcbfnmbkopoojfekhnkhdbieeh在Chrome(你可以找到'黑暗读者扩展在其他浏览器(例如Firefox)中。你可以玩;过滤您要使用深色主题的网址,甚至过滤自己的深色主题。以下是几个示例:

在此处输入图片说明

在此处输入图片说明

希望对您有所帮助。贝鲁兹

  • 是的......这一切都很好,但 Dark Reader 不知道 jupyter 笔记本应该为单词着色。没有语法着色,这使得这个选项成为禁忌。 (5认同)
  • 我认为这是最好的方法,因为我们通常需要它提供的深色主题,而且,只需单击一下即可轻松检查我们正在创建的文档的真实视觉效果。(发布时很重要) (2认同)
  • 但有一个问题。如果您尝试使用鼠标选择几个字符,则所选内容在黑色背景上不可见。 (2认同)
  • 我一开始也遇到了代码没有突出显示或分类的问题。您需要**将模式从动态更改为过滤器或过滤器+**。这极大地改变了黑暗读者的行为。 (2认同)

小智 11

使用FireFox插件“ Darker Jupyter ”。


Dev*_*esh 8

您可以按照以下步骤操作。

  1. pip install jupyterthemespip install --upgrade jupyterthemes升级到最新版本的主题。
  2. 之后列出您拥有的所有主题:jt -l
  3. 之后jt-t <themename>例如jt -t solarizedl


Vid*_*Pac 7

我的完整解决方案:

  1. 在 chrome 上获取 Dark Reader,这不仅可以为 Jupyter 提供出色的深色主题,还可以为您想要的每个网站提供深色主题(您可以使用不同的过滤器。我使用 Dynamic)。

  2. 将这些代码行粘贴到笔记本中,以便图例和轴变得可见:

from jupyterthemes import jtplot
jtplot.style(theme='monokai', context='notebook', ticks=True, grid=False)
Run Code Online (Sandbox Code Playgroud)

您已准备好参加迪斯科编码之夜!


Sar*_*hal 7

仅适用于暗模式:-

我已经使用 Raleway Font 来设计样式

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;
}
Run Code Online (Sandbox Code Playgroud)

要追加的内容现在开始

.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;
}
Run Code Online (Sandbox Code Playgroud)

Jupyter Notebook 的暗模式

Jupyter Notebook 的暗模式

  • 为什么它过时了? (2认同)

小智 6

要直接使用conda安装Jupyterthemes软件包,请使用:

conda install -c conda-forge jupyterthemes
Run Code Online (Sandbox Code Playgroud)

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


Cey*_*hun 5

conda install jupyterthemes
Run Code Online (Sandbox Code Playgroud)

在 Windows 中对我不起作用。我正在使用蟒蛇。

但,

pip install jupyterthemes
Run Code Online (Sandbox Code Playgroud)

在 Anaconda Prompt 工作。

  • 您需要为 conda 指定正确的集合:`conda install -c conda-forge jupyterthemes` (8认同)

Mad*_*hav 5

您可以使用运行笔记本中的 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')
Run Code Online (Sandbox Code Playgroud)

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


小智 5

如果您使用 google chrome 并想要一个深色主题,这样可以在 jupyter/网页中工作数小时,并且让代码中的配色方案保持可读性,那么另一种选择是使用“Web 内容的自动深色模式”实验中的标志 - chrome://flags - 我通常选择“启用选择性图像反转”选项。

  • 这是一个很酷的功能 - 感谢分享。 (2认同)