title: Looping through a function to plot several subplots, Python
body: <p>I have variables <code>x</code> and <code>y</code> </p>
  
  <pre><code>def function(a,b):
      x = x[(x&gt;a)*(x&lt;b)]
      y = y[(y&lt;a)*(y&gt;b)]
  
      # perform some fitting routine using curve_fit on x and y
  
      fig = plt.figure()
      ax = fig.add_subplot(111)
      phist,xedge,yedge,img = ax.hist2d(x,y,bins=20,norm=LogNorm())
      im = ax.imshow(phist,cmap=plt.cm.jet,norm=LogNorm(),aspect='auto')
      fig.colorbar(im,ax=ax)
      fig.show()
  </code></pre>
  
  <p>All works fine. But <strong>I have 6 pairs of different input parameters <code>a</code> and <code>b</code>. I would like to somehow call <code>function(a,b)</code> using a loop and plot the six different <code>x</code> and <code>y</code></strong> (corresponding to the 6 input pairs) <strong>as 6 subplots.</strong> </p>
  
  <p>like we do</p>
  
  <pre><code>ax1 = fig.add_subplot(231) # x vs y for a1,b1
  ax2 = fig.add_subplot(232) # x vs y for a2,b2
  ....
  ax6 = fig.add_subplot(236) # x vs y for a6,b6
  </code></pre>
  
  <p>I would like to get an idea of how to proceed to get the final subplot! </p>
  
  <p>I know that it can be done manually by specifying different variables, like <code>x1</code> and <code>y1</code> for the first input pair <code>a</code> and <code>b</code> and so on for the other 6 pairs <code>(x2,y2...,x6,y6)</code>. But it will be a very lengthy and confusing code. </p>