title: Automatically generate subplots based on length of a list
body: <p>I want to generate colorplot subplots based on a numpy array's length which I call dets. I want to use the array length to determine the right number of columns and rows for the subplots. If square, plot a square matrix of subplots, if not square, add another row. For starters, I have written some code to check if the array's length would create a square matrix of subplots with the following:</p>
  <pre><code>data_f = np.random.rand(len(dets),2,5)
  dets = np.arange(-5,-0.75,0.25)
  x = np.array([1,5,6,3,8,9,2,3,10,12,3])
  v = np.linspace(0,10,len(x))
  
  square = np.sqrt(len(dets))
  check_square = len(dets)%square
  non_square = 1
  
  print(len(data_f))
  
  if check_square == 0:
      nrows = int(np.sqrt(len(dets)))
      ncols = int(np.sqrt(len(dets)))
  else:
      nrows = int(np.sqrt(len(dets)))+non_square
      ncols = int(np.sqrt(len(dets)))
  
  fig, ax = plt.subplots(nrows, ncols, sharex='col', sharey='row')
  
  for i in range(nrows):
      for j in range(ncols):
          if i==0:
              im = ax[i,j].imshow(data_f[j],extent=(x.min(), x.max(), v.min(), v.max()),origin='lower',aspect='auto')
          else:
               im = ax[i,j].imshow(data_f[j+ncols*i],extent=(x.min(), x.max(), v.min(), v.max()),origin='lower',aspect='auto')
              
  
  </code></pre>
  <p>The output plot:</p>
  <p>This plots 17 plots but the resulting plots I cannot adjust because of the error</p>
  <p><img src="https://i.stack.imgur.com/dogAP.png" alt="" /></p>
  <p>This plots everything I want, except it always smushes the plots together in a weird way because of the following error:</p>
  <pre><code>---------------------------------------------------------------------------
  IndexError                                Traceback (most recent call last)
  ~\AppData\Local\Temp\1/ipykernel_4560/3817292743.py in &lt;module&gt;
        6             im = ax[i,j].imshow(data_f[j],extent=(x.min(), x.max(), v.min(), v.max()),origin='lower',aspect='auto')
        7         else:
  ----&gt; 8              im = ax[i,j].imshow(data_f[j+ncols*i],extent=(x.min(), x.max(), v.min(), v.max()),origin='lower',aspect='auto')
        9 
  
  IndexError: index 17 is out of bounds for axis 0 with size 17
  </code></pre>