如何编辑 JupyterLab 主题

How to edit a JupyterLab theme

我想编辑 JupyterLab 深色主题,以便可以清楚地阅读内联图上的轴标签。问题示例:

为了解决这个问题,我想将包含图像的输出单元格的背景颜色更改为灰色阴影。我使用 Chrome DevTools 检查网页,发现 class class="p-Widget jp-RenderedImage jp-mod-trusted jp-OutputArea-output".

我注意到我可以通过使用 JupyterLab Light Theme 或在 matplotlib 中使用 dark plotting theme 来解决这个问题,但是我想直接解决这个问题。我欢迎所有阅读资源的建议或指导,这将帮助我理解和解决这个问题。谢谢!

GitHub 上的相关问题:

相关的 SO 问题:

要编辑 JupypterLab 主题,您需要更改位于 jupyterlab/packages/[THEME NAME]/style/

中的文件 variables.css

您可以检查要更改的 JupyterLab 元素以找出其 class。我使用 Chrome DevTools ctrl+shift+i 并单击各种 div classes 直到找到我想要更改的那个。

获得要自定义的 div class 的名称后,将更改添加到 variables.css 文件。这是我更改的内容和结果。

.jp-RenderedImage {
  background-color: #A4A4A4
}

您可以使用由 JupyterLab 贡献者之一创建的 this gist (where the code in the first cell comes from) 来试验您对 variables.css 文件所做的更改。

看起来您显示的示例是因为绘图的 facecolor 是透明的。当我切换到 Jupyter 的黑暗主题时,我注意到我的情节也发生了这种情况。

这里有两个更新这个 Jupyter 配置的参考:

  1. https://ipython.readthedocs.io/en/stable/config/intro.html

总而言之,我打开了 ~/.ipython/profile_default 目录并创建了一个新的 ipython_config.py 文件(因为它还不存在)

cd ~/.ipython/profile_default/
vi ipython_config.py

在该文件中,我添加了行

c = get_config()
c.InlineBackend.print_figure_kwargs={'facecolor' : "w"}