title: Legend outside the plot in Python - matplotlib
body: <p>I'm trying to place a rather extensive legend outside my plot in matplotlib. The legend has quite a few entries, and each entry can be quite long (but I don't know exactly how long).</p>
  
  <p>Obviously, that's quite easy using</p>
  
  <pre><code>legendHandle = plt.legend(loc = "center left", bbox_to_anchor = (1, 0.5))
  </code></pre>
  
  <p>but the problem is that the legend is cut off by the edge of the window. I've spent quite a while searching for solutions for this. The best thing I could find so far was this:</p>
  
  <pre><code>box = ax.get_position()
  ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
  plt.legend(loc = "center left", bbox_to_anchor = (1, 0.5))
  </code></pre>
  
  <p>Unfortunately, this doesn't really solve my problem. Because of the explicit factor 0.8 applied to the box width, this only works with one specific combination of figure and legend width. If I resize the figure window, or if my legend entries have a different length, it doesn't work.</p>
  
  <p>I just don't understand how placing a legend outside the figure can be so difficult. I'm used to Matlab, and there it's as simple as</p>
  
  <pre><code>legend('Location', 'eastoutside')
  </code></pre>
  
  <p>Is there something similar in Python that I'm missing?</p>