Seven Jupyter Notebook Setups to Improve Readability | by Sabi Horvat | Towards Data Science

Using coding blocks, or cells, that execute separately- although they may have a sequence dependency- is very useful for data model development. The Jupyter Notebooks interface has a simplicity that is easy to learn. Once you are versed in the basics, allow me to share seven setup modifications or enhancements that increase the readability of these notebooks.
Seven Jupyter Notebook setups to increase readability:
Dark ThemesExecution TimeScratchpadSplit CellsCodefoldingCollapsible HeadingsTable of Contents (2)
Dark Themes
Execution Time
Scratchpad
Split Cells
Codefolding
Collapsible Headings
Table of Contents (2)
Nbextensions options account for setups 2–7 (all except the Dark Themes).
Most of these seven setups include options from within the jupyter_contrib_nbextensions. Please see the installation steps at readthedocs. For example, with pip:
pip install jupyter_contrib_nbextensions
or
pip install https://github.com/ipython-contrib/jupyter_contrib_nbextensions/tarball/master
Once installed, when you launch Jupyter Notebooks you’ll see the Nbextensions option at the top.
Upon clicking on Nbextensions, you’ll receive many options below.
When you click on an option, a description of the option will appear below the list (scroll down in the Jupyter Notebook). While the description for Split Cells Notebook below is brief, some extensions have more detailed descriptions.
Safety first. Dark themes are usually my first modification to default settings on software. Dark themes reduce the amount of eye strain by limiting the bright white lights which are more common as defaults. If I forget to set a dark theme, it doesn’t take long before I notice a drop in productivity and think to adjust the defaults.
To install Jupyter Themes:
pip install jupyterthemes
To view the theme options available type jt -l:
jt -l
Output:
Available Themes:  chesterish grade3 gruvboxd gruvboxl monokai oceans16 onedork solarizedd solarizedl
Not all of themes are dark themes actually. Examples of the themes are available on dunovank’s GitHub. If you want to customize your own theme, that is also available on the main GitHub page for Jupyter-Themes.
I prefer the chesterish theme. In order to see the toolbars, name, and kernels in the Jupyter environment after changing themes, you’ll want to add -T -N and -kl to the command respectively.
jt -t chesterish -T -N -kl
Restart the Jupyter kernel, re-open your notebook, and voila! You now have the same theme as the screen captures in this article.
However, plots and other images may not display as they would on a white background. For seaborn plots, the following command fixes this.
import seaborn as snssns.set_theme(style=”whitegrid”)
The Execution Time option allows you to see how long each cell takes to complete. Anyone working with models that take more than a couple minutes to execute can appreciate the ease of this time logging, but this is also helpful when comparing different options for cells while developing a new model.
Enable the ExecuteTime option in Nbextensions and see the execution time shared below the executed code block. In this case the cell executed in 203ms.
The Scratchpad option allows you to test code without temporarily creating and then deleting cell blocks.
Enable the Scratchpad option in Nbextensions.
The scratchpad button appears in the bottom right corner of the notebook.
Click on the Scratchpad button to open the scratchpad. The scratchpad is an empty cell block that can utilize what has already run on the notebook kernel. But the Scratchpad can be modified and run without modifying any of the notebook cells.
I find this a convenient place to lookup help details, print variables, or try something new without changing the existing notebook cells.
The Split Cells option is helpful for notebook appearance and readability.
Enable the Split Cells Notebook option in Nbextensions.
Play around with pressing the ← → button to make a cell half-width, then go either above or below the cell to the previous or next cell and press the button again to bring cells that were previously separated horizontally to the new vertical separation.
This can be particularly helpful with displaying data frames next to visualizations. This way, there is no need to scroll down to see either the data frame or visualization.
The Codefolding option enables an expansion arrow that is used to hide indented code, enhancing notebook readability and appearance.
Enable the Codefolding option in Nbextensions.
Click on the arrow that appears for the option to hide indented code.
The Collapsible Headings option is also helpful for notebook appearance and readability.
Enable the Collapsible Headings option in Nbextensions.
Using the arrows that are generated next to headings, collapse and expand the headings.
The Table of Contents (2) option is another great way to navigate through a lengthy notebook fast.
Enable the Table of Contents (2) option in Nbextensions.
Click on the Table of Contents icon that appears after enabled. The table with hyperlinks will load at the top left of the notebook, under the toolbar icons. Drag it downward into a comfortable position such as below.
When the need to navigate swiftly or read an overview of the section has passed, the Table of Contents can be removed from the notebook space by pressing its button once more.
These are relatively quick Jupyter setups that I find quite useful for readability. But there are many more great packages that work with Jupyter. I’d like to share three honorable mentions that are wonderful for certain situations, although not necessary for every notebook.
Honorable mentions:
LaTeX for markdown, such as MacTex
Autopep8 for the PEP 8 Style Guide
Jupyter Slideshows using RISE