title: How to fully delete plots from subplot and properly resize?
body: <p>I am trying to create a corner plot for an upcoming paper, but I'm running into difficulty.  I am creating an N x N array of subplots (currently, N = 6) and then deleting a bit over half of them.  The issue is that the figure doesn't seem to resize itself after I delete the extraneous subplots, so when I later add a legend using a dummy subplot, it exists in the area where a full row and column of deleted subplots were, thus enlarging the figure.  I've been working on this for several hours now and haven't found a solution.  Here is the MWE:</p>
  <pre><code>import matplotlib.pyplot as plt
  %matplotlib notebook
  
  n_char = 8
  
  # Set up the main figure.
  fig, ax = plt.subplots(n_char, n_char, figsize=(n_char, n_char))
  
  # Get rid of the axis labels unless it's on the left-most column or bottom-most row.
  for i in range(0, n_char):
  
      # For each row, loop over each column.
      for j in range(0, n_char):
  
          # If the plot isn't in the bottom-most row, get rid of the x-axis tick labels.
          if i != n_char - 1:
              ax[i, j].set_xticklabels([])
  
          # If the plot isn't in the left-most column, get rid of the y-axis tick labels.
          if j != 0:
              ax[i, j].set_yticklabels([])
  
  # Remove the plots that are repetitive or boring (plotting against the same characteristic).
  for i in range(0, n_char):
  
      # For each row, loop over each column.
      for j in range(0, n_char):
  
          # Delete the offending axes.
          if j &gt;= i:
              ax[i, j].remove()
  
  # Set the spacing between the plots to a much smaller value.
  fig.subplots_adjust(hspace=0.00, wspace=0.00)
  
  # Create a big plot for the legend.  Have the frame hidden.
  fig.add_subplot(111, frameon=False, xticks=[], yticks=[], xticklabels=[], yticklabels=[])
  
  # Create some dummy data to serve as the source of the legend.
  plt.scatter([10], [10], color=&quot;k&quot;, s=5, zorder=2, label=&quot;Targets&quot;)
  
  # Set the x-axis limits such that the dummy data point is invisible.
  fig.gca().set_xlim(-1, 1)
  
  # Add the legend to the plot.  Have it located in the upper right.
  plt.legend(scatterpoints=1, loc=&quot;upper right&quot;, fontsize=5)
  
  # Save the final plot.
  fig.savefig(&quot;./../Code Output/Other Plots/Corner_Plot_Test.png&quot;, bbox_inches=&quot;tight&quot;, dpi=500)
  </code></pre>
  <p>I have looked at many different questions here on Stack Overflow.  The two most promising candidates was <a href="https://stackoverflow.com/questions/61393441/delete-a-matplotlib-subplot-and-avoid-left-blanks">this one</a>, but I found the solution wasn't quite workable due to the large number of plots (and, to be frank, I didn't fully understand the solution).  I thought that the first answer in <a href="https://stackoverflow.com/questions/44970010/axes-class-set-explicitly-size-width-height-of-axes-in-given-units">this one</a> might also work, as I thought it was a sizing issue (i.e. the figure wasn't resizing, so creating a new subplot was creating one the size of the original figure), but all it did was resize the <em>entire</em> figure, so that didn't work either.</p>
  <p>To help, I will also include an image.  I took the output of the code above and edited it to show what I want:</p>
  <p><a href="https://i.stack.imgur.com/K3XEr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/K3XEr.png" alt="Image showing what I want the output to be" /></a></p>
  <p>I should add that if I <em>don't</em> add a subplot, the output is as I expected (i.e. it's the proper size), so the issue comes in when adding the subplot, i.e. the line <code>fig.add_subplot(111, frameon=False, xticks=[], yticks=[], xticklabels=[], yticklabels=[])</code>.</p>