Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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 '14 at 4:07
    
If so, you can alias ipython to just do that pretty easily. – Chris Arena Jan 17 '14 at 4:08
3  
ipython --matplotlib is better – tacaswell Jan 17 '14 at 21:38
up vote 38 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_config.py
  • ipython_kernel_config

Add the inline option for matplotlib to ipython_kernel_config.py:

c = get_config()
# ... Any other configurables you want to set
c.InteractiveShellApp.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
2  
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 '14 at 14:48
1  
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 '14 at 14:50
3  
This (as well as SillyBear's answer) stopped working with IPython 3. github.com/ipython/docker-notebook/pull/7#issuecomment-54729‌​770 suggests to use "c.IPKernel.matplotlib"... which doesn't work neither. – Pietro Battiston Mar 29 '15 at 10:39
3  
This answer worked for me. In IPython 3 there's apparently a new configuration file, ipython_kernel_config.py, that contains this option. Make a new profile (ipython profile create test) to get a default. – DGrady Jun 4 '15 at 0:07
2  
This option seems to have been renamed to c.InteractiveShellApp.matplotlib = "inline" – tiago Aug 26 '15 at 19:47

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 '14 at 15:22
1  
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 '14 at 1:07
7  
This no longer works (at least as of IPython 4). The command line options --matplotlib or --pylab are ignored. – tiago Aug 26 '15 at 19:45

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

In (the current) IPython 3.2.0 (Python 2 or 3)

Open the configuration file within the hidden folder .ipython

~/.ipython/profile_default/ipython_kernel_config.py

add the following line

c.IPKernelApp.matplotlib = 'inline'

add it straight after

c = get_config()
share|improve this answer

Further to @Kyle Kelley and @DGrady, here is the entry which can be found in the

$HOME/.ipython/profile_default/ipython_kernel_config.py (or whichever profile you have created)

Change

# Configure matplotlib for interactive use with the default matplotlib backend.
# c.IPKernelApp.matplotlib = none

to

# Configure matplotlib for interactive use with the default matplotlib backend.
c.IPKernelApp.matplotlib = 'inline'

This will then work in both ipython qtconsole and notebook sessions.

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.