Matplotlib figure size in Jupyter reset by inlining in Jupyter
<p>This question is more of a curiosity.</p>

<p>To change the default fig size to a custom one in matplotlib, one does</p>

<pre><code>from matplotlib import rcParams
from matplotlib import pyplot as plt
rcParams['figure.figsize'] = 15, 9
</code></pre>

<p>after that, figure appears with chosen size. </p>

<p>Now, I'm finding something new (never happened/noticed before just now): in a Jupyter notebook, when inlining matplotlib as </p>

<pre><code>%matplotlib inline
</code></pre>

<p>this apparently overwrites the <code>rcParams</code> dictionary restoring the default value for the figure size. Hence in oder to be able to set the size, I have to inline <code>matplotlib</code> <em>before</em> changing the values of the <code>rcParams</code> dictionary. </p>

<p>I am on a Mac OS 10.11.6, matplotlib version 1.5.1, Python 2.7.10, Jupyter 4.1.</p>

<p>IPython's inline backend <a href="https://github.com/ipython/ipykernel/blob/4.5.0/ipykernel/pylab/config.py#L45" rel="nofollow">sets some rcParams</a> when it is initialized. This is configurable, and you can override it with your own configuration:</p>

<pre><code># in ~/.ipython/ipython_config.py
c.InlineBackend.rc = {
    'figure.figsize': (15, 9)
}
</code></pre>

<p>The above would <strong>replace</strong> all of the rcParams that the inline backend sets, and you get total control. If you already have a matplotlib style that works nicely for inline output, you can tell the backend to leave everything alone:</p>

<pre><code>c.InlineBackend.rc = {}
</code></pre>

<p>If you want to change just a few values, rather than overriding the whole thing, you can use the dictionary <code>.update</code> method:</p>

<pre><code>c.InlineBackend.rc.update({'figure.figsize': (15, 9)})
</code></pre>

<p>In the future, the inline backend should be doing its defaults via matplotlib's nice new style mechanism, which should make it behave nicer in terms of respecting your preferences and allowing easier customization.</p>

python matplotlib plot jupyter