What does a 4-element tuple argument for 'bbox_to_anchor' mean in matplotlib?
<p>In the <a href="http://matplotlib.org/users/legend_guide.html#legend-location" rel="nofollow">"Legend location"</a> section of the "Legend guide" in the matplotlib website, there's a small script where line 9 is <code>plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.)</code>. All the tuples I've seen passed to <code>bbox_to_anchor</code> have 2 elements in it, but this one has 4. What does each element mean if the tuple passed has 4 elements? 
<br><br>
I was looking at it in the <code>pyplot.legend</code> <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.legend" rel="nofollow">docs</a>, and it said something about <code>bbox_transform</code> coordinates. So I looked around and found <code>matplotlib.transforms.Bbox</code> with a <a href="http://matplotlib.org/devel/transformations.html#matplotlib.transforms.Bbox" rel="nofollow"><code>static from_bounds(x0, y0, width, height)</code></a>. 
<br><br>
I was guessing the setup for the 4-tuple parameter was based on this <code>from_bounds</code>. I copied the script to Spyder, did <code>%matplotlib</code> in an Ipython console, and changed some values. It seemed to make sense, but when I tried only changing <code>.102</code> to something like <code>0.9</code>, the legend didn't change. I think the tuple is based on <code>from_bounds</code>, I just don't know why changing the last value in the tuple did nothing. </p>

<p>You're right, the 4-tuple in <code>plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3)</code> is set as <code>(x0, y0, width, height)</code> where <code>(x0,y0)</code> are the lower left corner coordinates of the bounding box.</p>

<p>While those parameters set the bounding box for the legend, the legend's actual vertical size is shrunk to the size that is needed to put the elements in. Further its position is determined only in conjunction with the <code>loc</code> parameter. The loc parameter sets the alignment of the legend inside the bounding box, such that for some cases, no difference will by seen when changing the <code>height</code>, compare e.g. plot (2) and (4).</p>

<p><a href="http://i.stack.imgur.com/OtHbK.png" rel="nofollow"><img src="http://i.stack.imgur.com/OtHbK.png" alt="enter image description here"></a> </p>

python matplotlib