title: Matplotlib Adding whitespace on both sides
body: <p>I am doing a plot with a very big legend on the top of the figure following the last example of this <a href="https://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot">link</a>.</p>
  
  <p>Since the font size of the legend must be very big, it happens that both on the right and on the left the legend is cropped. </p>
  
  <p>What I would like to do is adding some extra whitespace on the left and on the right of my image in order to let the legend fit in. More formally, the process must be this:</p>
  
  <ol>
  <li><p>Start with a plot without legend with figsize = (8,8). This is not a problem of course.</p></li>
  <li><p>Add some extra whitespace on the left and on the right. This would bring the figsize to be rectangular e.g. (12, 8). The initial plot must be on the center and looking squared. <strong>That is the critical point</strong></p></li>
  <li><p>Add the horizontal legend on the plot that now doesn't get cropped since the figsize has more space on the two sides.</p></li>
  </ol>
  
  <p>To solve this problem I have tried to:</p>
  
  <ul>
  <li><p>Use <code>fig.tight_layout()</code> with the option <code>pad</code> and <code>rect</code> as suggested by this <a href="https://stackoverflow.com/questions/14306986/how-to-put-more-whitespace-around-my-plots">link</a>, but it didn't work for me.</p></li>
  <li><p>I could follow what this <a href="https://stackoverflow.com/questions/46284867/matplotlib-legend-too-wide">link</a> suggests, but it doesn't fit with my needs because I can't reduce the font size of the legend and I can't change the figsize initally because otherwise the starting plot would look rectangular instead of squared.</p></li>
  <li><p>I have tried to use <code>subplots_adjust(w_space)</code>, but the problem persists.</p></li>
  </ul>
  
  <p>I let you with an example to reproduce my current situation:</p>
  
  <pre class="lang-py prettyprint-override"><code>fig, ax = plt.subplots(1, 1, figsize = (10,10))
  ax.plot(range(5),range(0,20,4), label="pippo")
  ax.plot(range(5),range(0,25,5), label="pappo")
  ax.plot(range(5),range(0,25,5), label="tp")
  ax.plot(range(5),range(0,25,5), label="minni")
  ax.plot(range(5),range(0,25,5), label="pluto")
  ax.plot(range(5),range(0,25,5), label="paperino")
  ax.plot(range(5),range(0,25,5), label="chicho")
  ax.plot(range(5),range(0,25,5), label="mela")
  ax.plot(range(5),range(0,25,5), label="pera")
  ax.plot(range(5),range(0,25,5), label="banana")
  
   # Shrink current axis's height by 10% on the bottom
  box = ax.get_position()
  ax.set_position([box.x0, box.y0 - box.height * 0.1,
                   box.width, box.height * 0.9])
  # Put a legend below current axis
  ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.2),
            fancybox=True, shadow=True, ncol=10, prop={'size':32})
  
  fig.savefig("check")
  </code></pre>