Jupyter Notebook “hacks” for cleaner, simpler Notebooks

samcha
Oct 5, 2018

--

1.) Make your plot settings “sticky”

Typing the same command more than two times is annoying. Run this at the top of your notebook to set a default size for your matplotlib plots:

matplotlib.rcParams[‘figure.figsize’] = (13,8)

You can also use this for other matplotlib settings like so:

matplotlib.rcParams['lines.linewidth'] = 2
matplotlib.rcParams['lines.color'] = 'r'

Or group them together:

matplotlib.rc('lines', linewidth=2, color='r')

(From matplotlib — Customizing matplotlib)

What does “rc” stand for? Apparently the suffix stands for “run command” and is a “fossil” in UNIX systems from CTSS, invented in the 1960's.

2.) Make your Jupyter Notebook wider

from IPython.core.display import display, HTMLdisplay(HTML(“<style>.container { width:80% !important; }</style>”))

Why waste all that wonderful space?

3.) Make your plots higher resolution

%config InlineBackend.figure_format = ‘retina’

4.) Link to other notebooks

# In Markdown cell:[Link text here](‘/path/notebook.ipynb’)

This goes a long way in organizing notebooks, so you don’t have to scroll through a bunch of DataFrame printouts to get to your fancy graphs at the end.

6.) Present your Notebook as slides

!jupyter nbconvert this_notebook.ipynb --to slides --post serve

Go to View > Cell Toolbar > Slideshow to group your cells into slides. This will allow you to arrow through slides once it is in the presentation.

My default settings:

I just run this at the top of every notebook.

import matplotlibmatplotlib.rcParams['figure.figsize'] = (13,8)%config InlineBackend.figure_format = 'retina'

Anything I can write about to help you find success in data science or trading? Tell me about it here: https://bit.ly/3mStNJG

--

--

samcha
samcha

Written by samcha

Python, trading, data viz. Get access to samchaaa++ for ready-to-implement algorithms and quantitative studies: https://samchaaa.substack.com/

No responses yet