title: How can I have shared axis labels for an arbitrarily sized grid of subplots in pyplot?
body: <p>I have seen some answers that get close to addressing what I need to do, but nothing quite like it.</p>
  
  <p>I have a function that produces a variable number of subplots, based on the size of an array that is passed to it. The problem is that, when I try to write the function using subplots(), I can't seem to add shared axis labels. Additionally, the shared x axis tends to be unreadable for large numbers of plots and I'm not sure how to deal with that.</p>
  
  <pre><code>def tilePlot(indivArray):
      names = list()
      num_rows = len(indivArray)
      num_cols = len(indivArray[0])
      for r in range(num_rows):
              for c in range(num_cols):
                      names.append(str(r)+str(c))
  
      f, names = plt.subplots(num_rows, num_cols, sharex='col', sharey='row')
  
      for r in range(num_rows):
          for c in range(num_cols):
  
              names[r][c].plot(indivArray[r][c].allValues)
              names[r][c].set_title(indivArray[r][c].name)
  
  
      f.subplots_adjust(hspace=.25)
  
      plt.setp([a.get_xticklabels() for a in f.axes[:]], visible=False)
  
      plt.show()
  </code></pre>
  
  <p>I tried rewriting the function to use add_subplot, but then I am not sure if there is a feasible way to make the subplots share axes.</p>
  
  <pre><code>def tilePlot2(indivArray):
      num_rows = len(indivArray)
      num_cols = len(indivArray[0])
  
      names = list()
      codes = list()
      counterlist = list()
  
      counter = 0
  
      for r in range(num_rows):
  
          names.append(list())
          codes.append(list())
          counterlist.append(list())
  
          for c in range(num_cols):
              counter+=1
              names[r].append(str(r)+str(c))
              codes[r].append(c)
              counterlist[r].append(counter)
  
  
  
      fig = plt.figure()
      ax = fig.add_subplot(111)    # The big subplot
  
  
      for r in range(num_rows):
          for c in range(num_cols):
  
              names[r][c]=fig.add_subplot(num_rows, num_cols, counterlist[r][c])
  
      # Turn off axis lines and ticks of the big subplot
      ax.spines['top'].set_color('none')
      ax.spines['bottom'].set_color('none')
      ax.spines['left'].set_color('none')
      ax.spines['right'].set_color('none')
      ax.tick_params(labelcolor='none', top='off', bottom='off', left='off', right='off')
  
      for r in range(num_rows):
          for c in range(num_cols):
  
              names[r][c].plot(indivArray[r][c].allValues)
              names[r][c].set_title(indivArray[r][c].name)
  
      # Set common labels
      ax.set_xlabel('Time (s)')
      ax.set_ylabel('RFU')
  
      fig.subplots_adjust(hspace=.25)
  
      plt.setp([a.get_xticklabels() for a in fig.axes[-1:]], visible=False)        
      plt.show()
  </code></pre>
  
  <p>I am sorry that my code is inelegant, I am new at Matplotlib. Thank you!</p>