Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Every time I launch iPython Notebook, the first command I run is

%matplotlib inline

Is there some way to change my config file so that when I launch iPython, it is automatically in this mode?

share|improve this question
    
Does 'ipython -pylab' work? –  Chris Arena Jan 17 at 4:07
    
If so, you can alias ipython to just do that pretty easily. –  Chris Arena Jan 17 at 4:08
    
ipython --matplotlib is better –  tcaswell Jan 17 at 21:38

3 Answers 3

up vote 10 down vote accepted

The configuration way

IPython has profiles for configuration, located at ~/.ipython/profile_*. The default profile is called profile_default. Within this folder there are two primary configuration files:

  • ipython_notebook_config.py - Runs before instantiating the notebook
  • ipython_config.py - Runs before instantiating any kernels

Add the inline option for matplotlib to ipython_notebook_config.py:

c = get_config()
# ... Any other configurables you want to set
c.IPKernelApp.matplotlib = 'inline'

matplotlib vs. pylab

Usage of %pylab to get inline plotting is discouraged.

It introduces all sorts of gunk into your namespace that you just don't need.

%matplotlib on the other hand enables inline plotting without injecting your namespace. You'll need to do explicit calls to get matplotlib and numpy imported.

import matplotlib.pyplot as plt
import numpy as np

The small price of typing out your imports explicitly should be completely overcome by the fact that you now have reproducible code.

share|improve this answer
1  
Thanks. I had actually seen this config option in the matplotlib docs, but wasn't sure whether it just set the matplotlib backend that would take effect once you manually called %matplotlib or whether it both set the default backend and automatically set it up for use immediately in the iPython environment. –  8one6 Jan 17 at 14:48
    
To add to @Kyle Kelley's edit regarding matplotlib vs pylab, iPython makes it very easy to automatically execute arbitrary python code every time you launch using Profiles. I believe it is quite common to have a profile where you automatically do common imports like import numpy as np; import pandas as pd; import matplotlib.pyplot as plt, etc. NB: pylab is not the same thing as pyplot. It must have taken me a month to realize that. –  8one6 Jan 17 at 14:50

I think what you want might be to run the following from the command line:

ipython notebook --matplotlib=inline

If you don't like typing it at the cmd line every time then you could create an alias to do it for you.

share|improve this answer
1  
Please change your post to --matplotlib inline and remove the --pylab stuff. See this post of an ipython devel why: carreau.github.io/posts/10-No-PyLab-Thanks.ipynb.html –  Jakob Jan 22 at 15:22
    
One note about matplotlib=inline: It will slow down every kernel you launch, regardless of whether you want to use matplotlib. –  Kyle Kelley Oct 6 at 1:07

In your ipython_config.py file, search for the following lines

# c.InteractiveShellApp.matplotlib = None

and

# c.InteractiveShellApp.pylab = None

and uncomment them. Then, change None to the backend that you're using (I use 'qt4') and save the file. Restart IPython, and matplotlib and pylab should be loaded - you can use the dir() command to verify which modules are in the global namespace.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.