My Python setup

In this post, I summarise my custom settings for my IPython, Matplotlib and IPython Notebook for my Windows machine at work.

IPython

First some aesthetic preferences:

# select qt backend for plotting from terminal
from IPython.terminal.ipapp import TerminalIPythonApp
TerminalIPythonApp.matplotlib='qt'

c = get_config()
# bigger plots in IPython notebooks
c.InlineBackend.rc = {'figure.figsize': (16.0, 8.0), 'savefig.dpi': 72}

These are for productivity, mainly:

# always reload packages interactively
%load_ext autoreload
%autoreload 2

# import mainly used packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# change to pandas default "beautiful" style
pd.options.display.mpl_style = 'default'
# but keep sans-serif fonts (instead of monospace)
plt.rcParams['font.family'] = 'sans-serif'

Matplotlib

For coherence with my employer’s style guide, I set my plot font to Arial with the following two lines:

font.family         : sans-serif
font.sans-serif     : Arial

All this results in the following default plot appearance (here for a Pandas area plot of multiple timeseries):

ipython-pandas-area-plot

Share as Gist toolbar button

Pre-requisite: you must have a GitHub account and create a Personal access token for your share button, so that it may upload code in your name.

Once that is prepared, get the file gist.js from minrk’s ipython extensions GitHub repository and place it in in the folder .ipython/nbextensions.

Then add the following lines to file custom.js, located in your profile:

require(["nbextensions/gist"], function (gist_extension) {
    console.log('gist extension loaded');
    gist_extension.load_ipython_extension();
});

The next time you launch ipython notebook, a share button should appear in every notebook’s toolbar. The first time you click it, you must paste your GitHub access token. From there on, it will work automatically. Here is how it looks in action:

ipython-share-button

(And here is the link to the corresponding Notebook: urbs-result-plot.ipynb.)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.