前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jupyter notebook 主题自定义

jupyter notebook 主题自定义

作者头像
小嗷犬
发布2022-11-15 15:55:41
4860
发布2022-11-15 15:55:41
举报

✅作者简介:人工智能专业本科在读,喜欢计算机与编程,写博客记录自己的学习历程。 🍎个人主页:小嗷犬的博客 🍊个人信条:为天地立心,为生民立命,为往圣继绝学,为万世开太平。 🥭本文内容:jupyter notebook 主题自定义


jupyter notebook 主题自定义


jupyter notebook 是我们常用的 Python 编辑环境,但是它的配色风格与字体风格却有些单调,使用久了难免有些厌倦,本文将教大家更改 jupyter notebook 的主题和字体。

1.jupyterthemes 的安装

jupyterthemes 是一个开源的 jupyter 插件,它为我们提供了多种配色风格和字体。

开源地址:https://github.com/dunovank/jupyter-themes

我们这里用pip命令安装:

代码语言:javascript
复制
pip install jupyterthemes

2.jupyterthemes 内容与用法

摘自开源项目README.md文件:

2.1 JT Customizable Features(可自定义的部分)

2.1.1 plotting style

plotting style
plotting style

2.1.2 markdown/equations

markdown/equations
markdown/equations

2.1.3 pandas dataframes

pandas dataframes
pandas dataframes

2.1.4 command palette

command palette
command palette

2.2 Command Line Usage(命令行用法)

代码语言:javascript
复制
jt  [-h] [-l] [-t THEME] [-f MONOFONT] [-fs MONOSIZE] [-nf NBFONT]
    [-nfs NBFONTSIZE] [-tf TCFONT] [-tfs TCFONTSIZE] [-dfs DFFONTSIZE]
    [-m MARGINS] [-cursw CURSORWIDTH] [-cursc CURSORCOLOR] [-vim]
    [-cellw CELLWIDTH] [-lineh LINEHEIGHT] [-altp] [-altmd] [-altout]
    [-P] [-T] [-N] [-r] [-dfonts]

2.2.1 Description of Command Line options(用法描述)

cl options

arg

default

Usage help

-h

List Themes

-l

Theme Name to Install

-t

Code Font

-f

Code Font-Size

-fs

11

Notebook Font

-nf

Notebook Font Size

-nfs

13

Text/MD Cell Font

-tf

Text/MD Cell Fontsize

-tfs

13

Pandas DF Fontsize

-dfs

9

Output Area Fontsize

-ofs

8.5

Mathjax Fontsize (%)

-mathfs

100

Intro Page Margins

-m

auto

Cell Width

-cellw

980

Line Height

-lineh

170

Cursor Width

-cursw

2

Cursor Color

-cursc

Alt Prompt Layout

-altp

Alt Markdown BG Color

-altmd

Alt Output BG Color

-altout

Style Vim NBExt*

-vim

Toolbar Visible

-T

Name & Logo Visible

-N

Kernel Logo Visible

-kl

Reset Default Theme

-r

Force Default Fonts

-dfonts

2.3 Command Line Examples(用例)

第2行为可选的主题类型:

代码语言:javascript
复制
# list available themes
# onedork | grade3 | oceans16 | chesterish | monokai | solarizedl | solarizedd
jt -l

# select theme...
jt -t chesterish

# restore default theme
# NOTE: Need to delete browser cache after running jt -r
# If this doesn't work, try starting a new notebook session.
jt -r

# toggle toolbar ON and notebook name ON
jt -t grade3 -T -N

# toggle kernel logo.  kernel logo is in same container as name
# toggled with -N.  That means that making the kernel logo visible is
# pointless without also making the name visible
jt -t grade3 -N -kl

# set code font to 'Roboto Mono' 12pt
# (see monospace font table below)
jt -t onedork -f roboto -fs 12

# set code font to Fira Mono, 11.5pt
# 3digit font-sizes get converted into float (115-->11.5)
# 2digit font-sizes > 25 get converted into float (85-->8.5)
jt -t solarizedd -f fira -fs 115

# set font/font-size of markdown (text cells) and notebook (interface)
# see sans-serif & serif font tables below
jt -t oceans16 -tf merriserif -tfs 10 -nf ptsans -nfs 13

# adjust cell width (% screen width) and line height
jt -t chesterish -cellw 90% -lineh 170

# or set the cell width in pixels by leaving off the '%' sign
jt -t solarizedl -cellw 860

# fix the container-margins on the intro page (defaults to 'auto')
jt -t monokai -m 200

# adjust cursor width (in px) and make cursor red
# options: b (blue), o (orange), r (red), p (purple), g (green), x (font color)
jt -t oceans16 -cursc r -cursw 5

# choose alternate prompt layout (narrower/no numbers)
jt -t grade3 -altp

# my two go-to styles
# dark
jt -t onedork -fs 95 -altp -tfs 11 -nfs 115 -cellw 88% -T
# light
jt -t grade3 -fs 95 -altp -tfs 11 -nfs 115 -cellw 88% -T

2.4 字体(代码单元格)

2.4.1 Monospace Fonts (code cells)

-f arg

Monospace Font

anka

Anka/Coder

anonymous

Anonymous Pro

aurulent

Aurulent Sans Mono

bitstream

Bitstream Vera Sans Mono

bpmono

BPmono

code

Code New Roman

consolamono

Consolamono

cousine

Cousine

dejavu

DejaVu Sans Mono

droidmono

Droid Sans Mono

fira

Fira Mono

firacode

Fira Code

generic

Generic Mono

hack

Hack

hasklig

Hasklig

inconsolata

Inconsolata-g

inputmono

Input Mono

iosevka

Iosevka

liberation

Liberation Mono

meslo

Meslo

office

Office Code Pro

oxygen

Oxygen Mono

roboto

Roboto Mono

saxmono

saxMono

source

Source Code Pro

sourcemed

Source Code Pro Medium

sudovar

Sudo Variable

ptmono

PT Mono

ubuntu

Ubuntu Mono

2.4.2 Sans-Serif Fonts

-nf/-tf arg

Sans-Serif Font

opensans

Open Sans

droidsans

Droid Sans

exosans

Exo_2

latosans

Lato

ptsans

PT Sans

robotosans

Roboto

sourcesans

Source Sans Pro

2.4.3 Serif Fonts

-nf/-tf arg

Serif Font

loraserif

Lora

ptserif

PT Serif

georgiaserif

Georgia

cardoserif

Cardo

crimsonserif

Crimson Text

ebserif

EB Garamond

merriserif

Merriweather

neutonserif

Neuton

goudyserif

Sorts Mill Goudy

3.如何设置导入的字体

笔者对插件提供的主题配色比较满意,但插件中没有包含笔者喜欢的Consola字体,于是笔者便自己导入字体来设置,下面提供教程。

首先让我们找到你的 Python 安装地址,然后打开以下路径的文件:

代码语言:javascript
复制
你的Python位置\Lib\site-packages\jupyterthemes\stylefx.py

大概在文件的524行,我们按格式:

代码语言:javascript
复制
    fonts = {'mono':
             {命令中使用的字体名:[字体名,字体所在的文件夹的名称]
             ...
             }

加入自己的字体名称,红框为笔者添加的字体:

文件1
文件1

除此之外,我们还要将对应的字体文件放到对应的位置。

进入以下路径:

代码语言:javascript
复制
你的Python位置\Lib\site-packages\jupyterthemes\fonts

选择你刚刚添加的字体类型:

文件夹1
文件夹1

进入对应分类子文件夹下,创建与你字体同名的文件夹:

文件夹2
文件夹2

将你要导入的字体改好对应的名字然后放入该文件夹:

文件夹3
文件夹3

然后就可以在命令行中设置自己的字体了。

4.自用主题字体分享

以下为笔者自己在用的主题和字体:

jupyter notebook1
jupyter notebook1
jupyter notebook2
jupyter notebook2

设置命令(需要Consola字体):

代码语言:javascript
复制
jt -t onedork -f consola -fs 14 -cellw 80% -ofs 14 -dfs 14 -T
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-11-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • jupyter notebook 主题自定义
  • 1.jupyterthemes 的安装
  • 2.jupyterthemes 内容与用法
    • 2.1 JT Customizable Features(可自定义的部分)
      • 2.1.1 plotting style
      • 2.1.2 markdown/equations
      • 2.1.3 pandas dataframes
      • 2.1.4 command palette
    • 2.2 Command Line Usage(命令行用法)
      • 2.2.1 Description of Command Line options(用法描述)
    • 2.3 Command Line Examples(用例)
      • 2.4 字体(代码单元格)
        • 2.4.1 Monospace Fonts (code cells)
        • 2.4.2 Sans-Serif Fonts
        • 2.4.3 Serif Fonts
    • 3.如何设置导入的字体
    • 4.自用主题字体分享
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档