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?
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?
The configuration way
IPython has profiles for configuration, located at
~/.ipython/profile_*
. The default profile is calledprofile_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
: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.The small price of typing out your imports explicitly should be completely overcome by the fact that you now have reproducible code.
In your
ipython_config.py
file, search for the following linesand
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 thedir()
command to verify which modules are in the global namespace.I think what you want might be to run the following from the command line:
If you don't like typing it at the cmd line every time then you could create an alias to do it for you.
The setting was disabled in
Jupyter 5.X
and higher by adding below codeAnd in previous versions it has majorly been a warning. But this not a big issue because Jupyter uses concepts of
kernels
and you can find kernel for your project by running below commandThis gives me the path to the kernel folder. Now if I open the
/Users/tarunlalwani/Documents/Projects/SO/notebookinline/bin/../share/jupyter/kernels/python3/kernel.json
file, I see something like belowSo you can see what command is executed to launch the kernel. So if you run the below command
So now if we update our
kernel.json
file toAnd if I run
jupyter notebook
the graphs are automaticallyinline
Note the below approach also still works, where you create a file on below path
~/.ipython/profile_default/ipython_kernel_config.py
But the disadvantage of this approach is that this is a global impact on every environment using python. You can consider that as an advantage also if you want to have a common behaviour across environments with a single change.
So choose which approach you would like to use based on your requirement
In (the current) IPython 3.2.0 (Python 2 or 3)
Open the configuration file within the hidden folder .ipython
add the following line
add it straight after
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
to
This will then work in both ipython qtconsole and notebook sessions.