How to set the matplotlib figure default size in ipython notebook?

PythonMatplotlibJupyter Notebook

Python Problem Overview


I use "$ipython notebook --pylab inline" to start the ipython notebook. The display matplotlib figure size is too big for me, and I have to adjust it manually. How to set the default size for the figure displayed in cell?

Python Solutions


Solution 1 - Python

Worked liked a charm for me:

matplotlib.rcParams['figure.figsize'] = (20, 10)

Solution 2 - Python

I believe the following work in version 0.11 and above. To check the version:

$ ipython --version

It may be worth adding this information to your question.

Solution:

You need to find the file ipython_notebook_config.py. Depending on your installation process this should be in somewhere like

.config/ipython/profile_default/ipython_notebook_config.py

where .config is in your home directory.

Once you have located this file find the following lines

# Subset of matplotlib rcParams that should be different for the inline backend.
# c.InlineBackend.rc = {'font.size': 10, 'figure.figsize': (6.0, 4.0), 'figure.facecolor': 'white', 'savefig.dpi': 72, 'figure.subplot.bottom': 0.125, 'figure.edgecolor': 'white'}

Uncomment this line c.InlineBack... and define your default figsize in the second dictionary entry.

Note that this could be done in a python script (and hence interactively in IPython) using

pylab.rcParams['figure.figsize'] = (10.0, 8.0)

Solution 3 - Python

Just for completeness, this also works

from IPython.core.pylabtools import figsize
figsize(14, 7)

It is a wrapper aroung the rcParams solution

Solution 4 - Python

If you don't have this ipython_notebook_config.py file, you can create one by following the readme and typing

ipython profile create

Solution 5 - Python

In iPython 3.0.0, the inline backend needs to be configured in ipython_kernel_config.py. You need to manually add the c.InlineBackend.rc... line (as mentioned in Greg's answer). This will affect both the inline backend in the Qt console and the notebook.

Solution 6 - Python

plt.rcParams['figure.figsize'] = (15, 5)

Solution 7 - Python

You can use "run commands" rc to change the default figure size:

plt.rc('figure', figsize=(w,h))

Solution 8 - Python

So, a working solution on macos is

echo "
c.InlineBackend.rc = {
         'font.size': 10,
         'figure.figsize': (25.0, 5.0),
         'figure.facecolor': 'white', 
         'savefig.dpi': 72,
         'figure.subplot.bottom': 0.125,
         'figure.edgecolor': 'white'
}
" >> "$(ipython locate profile)/ipython_kernel_config.py"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbigbugView Question on Stackoverflow
Solution 1 - PythonSubspacianView Answer on Stackoverflow
Solution 2 - PythonGregView Answer on Stackoverflow
Solution 3 - PythongsmafraView Answer on Stackoverflow
Solution 4 - PythonanmolView Answer on Stackoverflow
Solution 5 - PythonPuggieView Answer on Stackoverflow
Solution 6 - PythonTomas G.View Answer on Stackoverflow
Solution 7 - PythoniacobView Answer on Stackoverflow
Solution 8 - PythonlovasoaView Answer on Stackoverflow