title: populating matplotlib subplots through a loop and a function
body: <p>I need to draw subplots of a figure through loop iterations; each iteration calls a function defined in another module (=another py file), which draws a pair of subplots. Here is what I tried -- and alas does not work:</p>
  
  <p>1) Before the loop, create a figure with the adequate number of rows, and 2 columns:</p>
  
  <pre><code> import matplotlib.pyplot as plt     
   fig, axarr = plt.subplots(nber_rows,2)
  </code></pre>
  
  <p>2) Inside the loop, at iteration number iter_nber, call on the function drawing each subplot:      </p>
  
  <pre><code> fig, axarr = module.graph_function(fig,axarr,iter_nber,some_parameters, some_data)
  </code></pre>
  
  <p>3) The function in question is basically like this; each iteration creates a pair of subplots on the same row:</p>
  
  <pre><code> def graph_function(fig,axarr,iter_nber,some_parameters, some_data):
  
       axarr[iter_nber,1].plot(--some plotting 1--)
       axarr[iter_nber,2].plot(--some plotting 2--)
  
       return fig,axarr
  </code></pre>
  
  <p>This does not work.  I end up with an empty figure at the end of the loop.
  I have tried various combinations of the above, like leaving only axarr in the function's return argument, to no avail. Obviously I do not understand the logic of this figure and its subplots.</p>
  
  <p>Any suggestions much appreciated.</p>