Jupyter Notebook

How to Change the Theme in Jupyter Notebook

Jupyter notebook is an easy-to-use environment that provides data science users with an interacting interface to create and share documents. It gives the facility to develop, verify, and modify code. Users can use the Jupyter notebook to perform tasks of data science, such as data analysis, numerical simulation, statistical modeling, deep learning, machine learning, data cleaning, and transformation.

Jupyter notebook has two components: front-end page of the web browser and the back-end kernel. Data user writes code at the front page then the kernel runs this code and returns the result.

In this article, we will discuss changing the theme in the Jupyter notebook.

What is a Theme in a Jupyter notebook?

A theme in Jupyter notebook defines the appearance of toolbars, buttons, and all visual elements that an interface possesses. By default, the Jupyter notebook has a light theme and it does not include any built-in option to change the theme.

Many users like to have a dark theme. We can change the theme in the jupyter notebook by installing an open-source library i.e., Jupyter themes by ‘Kyle Dunovan’.

How to install the theme in Jupyter theme?

You can install a new theme in the Jupyter notebook by implementing the following steps:

Step 1: Install Jupyter theme library

You can install the Jupyter theme library on your notebook using two methods: conda and pip.

Installation with conda:

conda install -c conda-forge

Installation with pip:

pip install jupyter themes

you can also upgrade the already installed Jupyter notebook themes by using the following command:

pip install –upgrade jupyterthemes

Step 2: List available jupyter themes 

After installation jupyter theme, you can display a list of available themes by using the following command:

!jt -l

The above command will show the list of available themes.

Step 3: Change jupyter notebook theme

Choose the theme you want to apply and set it with the following given command:

!jt -t <theme-name>

For example, here we applied themes ‘chesterish’ and ‘solarizedl ’respectively.

!jt -t chesterish

!jt -t solarizedl

To complete the process of applying the theme, refresh the page or open a new Python notebook to view changes.

How to restore the original theme in the Jupyter notebook?

To restore the original theme, the following command can be used:

!jt –r

The toolbar, filename, and kernel logo are all by default hidden when the notebook’s theme is changed to one of the above themes. You can enable these options in the Jupyter notebook by using a few commands that we have discussed below:

Enabling other features of the theme

Enable the filename by using this command:

!jt -t [theme name] -T

To enable filename and logo use this command:

!jt -t [theme name] -N

To enable kernel log use this command:

!jt -t [theme name] -kl

You can also change the theme and enable all options including the toolbar, filename, logo, and kernel logo in same command line statement:

!jt -t [theme name] -T -N –kl

Font Features in jupyter theme

Jupyter notebook provides the feature of changing code font, font size, notebook font, and notebook font size.

Use the following command to work on the font in the Jupyter notebook:

!jt [arg] [FONT or FONTSIZE]
Options Arguments
Code font Cf
Code font size Cfs
Notebook font Nf
Notebook font size Nfs

Table 1: Examples of font arguments

You can also use other options to customize in Jupyter themes such as Cell width, Line height, Plotting style, Cursor width, Cursor color, and many more options. It also gives the option to change the plotting style of figures by using the following command:

jtplot.style()

Conclusion

In this article, we learned how to change the theme in the Jupyter notebook. Jupyter theme is an open-source library to handle the visual presentation of the jupyter notebook. It can make the interface of the jupyter notebook easy and attractive to use. You can easily change your default jupyter notebook theme by following the above steps.

About the author

Samreena Aslam

Samreena Aslam holds a master’s degree in Software Engineering. Currently, she's working as a Freelancer & Technical writer. She's a Linux enthusiast and has written various articles on Computer programming, different Linux flavors including Ubuntu, Debian, CentOS, and Mint.