115

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?

iacob
  • 7,935
  • 4
  • 26
  • 52
bigbug
  • 40,984
  • 35
  • 71
  • 92

7 Answers7

129

Worked liked a charm for me:

matplotlib.rcParams['figure.figsize'] = (20, 10)
Eric O Lebigot
  • 81,422
  • 40
  • 198
  • 249
Subspacian
  • 1,739
  • 1
  • 13
  • 6
  • 21
    I don't know how idiomatic this is, but I adjusted this for my jupyter notebook to get it to work: `import matplotlib.pyplot as plt` `%matplotlib inline` `plt.rcParams['figure.figsize'] = (20.0, 10.0)` – brycemcd Aug 20 '16 at 18:33
  • 9
    There is also `plt.rc('figure', figsize=(20.0, 10.0))` – joelostblom May 19 '17 at 14:45
  • 2
    Quite weird, but after some update I need to split `%matplotlib inline` and `plt.rc(...)` across different cells for the latter to work. Same true for `matplotlib.rcParams[...]` – uranix May 21 '18 at 08:13
  • 3
    Also make sure this line is after `%matplotlib inline` – Rishabh Agrahari Sep 26 '18 at 17:29
128

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)
Greg
  • 9,973
  • 1
  • 40
  • 47
  • 6
    In ipython 2.0 the config file is in .ipython/profile_default/ipython_notebook_config.py – Fabian Pedregosa Apr 05 '14 at 06:18
  • 1
    In older versions of iPython, `ipython_notebook_config.py` doesn't contain the line to configure the inline backend. Since the configuration file is not automatically updated when you update iPython (at least on Windows), you need to delete it and generate a new config file by running `ipython profile create` as suggested by @anmol below. – Puggie Jan 15 '15 at 11:26
  • 1
    You can locate existing profiles with `ipython profile locate`. – j08lue May 07 '15 at 12:59
  • 23
    And if you're using matplotlib instead of pyplot, the interactive command is ```matplotlib.rcParams['figure.figsize'] = (10.0, 8.0)``` – Luke Jul 21 '15 at 21:38
  • I'm using jupyter 4.1.0-6 with python-ipykernel 4.5.2-3 and ipython 5.3.0-1 (all of them on Arch) and I have no file titled `ipython_notebook_config.py` under my `~`. Any idea how things may have changed in the most recent versions? – Pastafarianist Sep 25 '17 at 13:28
  • If you are using jupyter notebook, update `~/.ipython/profile_default/ipython_kernel_config.py` instead of `~.ipython/profile_default/ipython_notebook_config.py` – E.K. Feb 07 '18 at 15:27
19

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

ipython profile create
anmol
  • 611
  • 5
  • 7
19

Just for completeness, this also works

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

It is a wrapper aroung the rcParams solution

gsmafra
  • 2,093
  • 15
  • 22
8

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.

Community
  • 1
  • 1
Puggie
  • 3,437
  • 2
  • 27
  • 39
5
plt.rcParams['figure.figsize'] = (15, 5)
Thomas G.
  • 1,832
  • 15
  • 18
0

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

plt.rc('figure', figsize=(w,h))
iacob
  • 7,935
  • 4
  • 26
  • 52