title: `plt.legend` in matplotlib, seaborn: How does the `loc` parameter work?
body: <ul>
  <li>I am a beginner in Python doing an online course. The following is an abstracted version of a given solution in the course.</li>
  <li>In one exercise a <code>seaborn</code> plot is generated and a <code>legend</code> is added.</li>
  <li><strong>Issue:</strong> I do not understand how the legend is on the right side based on the parameters that are used. How is <code>loc = 'center left'</code> placing the <code>legend</code> on the right side of the plot?</li>
  <li>The <a href="https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html" rel="nofollow noreferrer"><code>matplotlib</code> manual</a> says:</li>
  </ul>
  <blockquote>
  <p>The strings 'upper center', 'lower center', 'center left', 'center
  right' place the legend at the center of the corresponding edge of the
  axes/figure.</p>
  </blockquote>
  <ul>
  <li>I am sure that there is a logical answer but I am not able to see it :).</li>
  </ul>
  <hr />
  <h2>Code Listing</h2>
  <pre><code>import pandas as pd
  import seaborn as sb
  
  # https://www.geeksforgeeks.org/different-ways-to-create-pandas-dataframe/
  # initialize data of lists.
  data = {'Name':['Tim', 'Tom', 'Cindy', 'Mandy'],
          'Age':[20, 21, 19, 18],
          'Gender':['Male', 'Male', 'Female', 'Female']}
   
  # Create DataFrame
  df = pd.DataFrame(data)
  
  sb.barplot(data = df, x = 'Name', y = 'Age',  hue = 'Gender')
  plt.legend(loc = 'center left', bbox_to_anchor = (1, 0.5)) # legend to right of figure
  </code></pre>
  <hr />
  <h2>Screenshots</h2>
  <p><a href="https://i.stack.imgur.com/zey9r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zey9r.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/1iJpj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1iJpj.png" alt="enter image description here" /></a></p>
  <p><em>(<a href="https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html" rel="nofollow noreferrer">https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html</a>)</em></p>