3

I use iPython Notebook for scientific applications and I'm always plotting experimental data sets. The default image rendering and color cycling behavior of the combination of iPython Notebook and Matplotlib is pretty bad, but it's great after the following tweaks.

# ipython notebook specific
%pylab inline

# imports
from matplotlib import pyplot as plt
import matplotlib as mpl
from seaborn.apionly import set_palette
from IPython.display import set_matplotlib_formats

# configure plotting
set_matplotlib_formats('pdf', 'svg')
set_palette('Set1', n_colors=15, desat=None)
mpl.rcParams['figure.figsize']=(12.0,2.0)

I don't want to have to enter these manually in every notebook. How can I have these executed for all notebooks I'll ever create?

nick_name
  • 1,283
  • 3
  • 23
  • 37

1 Answers1

2

You can create Python files in $HOME/.ipython/profile_default/startup/ that contains the code you want executed at startup.

For example, you can create $HOME/.ipython/profile_default/startup/00-init.py:

# imports
from matplotlib import pyplot as plt
import matplotlib as mpl
from seaborn.apionly import set_palette
from IPython.display import set_matplotlib_formats

# configure plotting
set_matplotlib_formats('pdf', 'svg')
set_palette('Set1', n_colors=15, desat=None)
mpl.rcParams['figure.figsize']=(12.0,2.0)

Note that IPython magics are not supported here, so %matplotlib inline won't work. This question deals with making %matplotlib inline the default.

You should be aware that if you change the defaults for your IPython environment, your notebooks may not work on other people's IPython installations.

Community
  • 1
  • 1
shadanan
  • 1,660
  • 13
  • 12