matplotlib place axes within figure box
<p>This is my code (I am running it in a jupyter notebook on OS X )</p>

<pre><code>% matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure()
fig.set_facecolor('gray')
ax = fig.add_axes([0.2, 0.2, 0.2, 0.2])
print fig.get_figwidth()
</code></pre>

<p>I was expecting to see a large gray figure box with a small white axes box in the bottom left hand corner. What I get is a small white axes box with a small gray box surrounding it. </p>

<p>I am obviously missing some setting or other. How do I get what I was expecting?</p>

<p><a href="http://i.stack.imgur.com/1WT2o.png" rel="nofollow"><img src="http://i.stack.imgur.com/1WT2o.png" alt="What I see"></a></p>

<p>After some more experimentation and digging I found the answer in the <a href="http://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-matplotlib" rel="nofollow">matplotlib magic</a> documentation referenced from <a href="http://stackoverflow.com/questions/37864735/matplotlib-and-ipython-notebook-displaying-exactly-the-figure-that-will-be-save?rq=1">here</a>.</p>

<p>The ipython magics are enforcing bbox_inches='tight' by default. which causes the figure bbox to shrink to fit the axes.</p>

<p>The trick is to add the magic line</p>

<p><code>% config InlineBackend.print_figure_kwargs = {'bbox_inches':None}</code></p>

python matplotlib