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?
You can use the magic function %matplotlib inline to enable the inline plotting, where the plots/graphs will be displayed just below the cell where your plotting commands are written. It provides interactivity with the backend in the frontends like the jupyter notebook.
%matplotlib inline sets the backend of matplotlib to the 'inline' backend: With this backend, the output of plotting commands is displayed inline within frontends like the Jupyter notebook, directly below the code cell that produced it. The resulting plots will then also be stored in the notebook document.
So %matplotlib inline is only necessary to register this function so that it displays in the output. Running import matplotlib. pyplot as plt also registers this same function, so as of now it's not necessary to even use %matplotlib inline if you use pyplot or a library that imports pyplot like pandas or seaborn.
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.py
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With