title: Python: create 3 panel plots within a loop
body: <p>I want to produce 6 plots with two on one page, so in total 3 pages 3 panel plots. And I want to do this within a loop.</p>
  
  <p>Here my code:</p>
  
  <pre><code>l=np.size(lon)
  n=np.size(lat)
  t=np.size(years) # where years is a list like (7039,7040,7041)
  prec_avg=np.zeros((t,n,l))
  prec_sum=np.zeros((t,n,l))
  
  for y in range(0,3):
      fig = plt.figure()
      fig.subplots_adjust(hspace=0.4, wspace=0.2,top=0.95, right=0.95)
  
      i=y*5
      k=i+5
  
      prec_avg[y,:,:]=np.mean(prec[i:k,:,:],axis=0)
      prec_sum[y,:,:]=np.sum(prec[i:k,:,:],axis=0)
      # ----- create plots -------------------------------------------------------
      lon, lat = np.meshgrid(lon,lat)
  
      ax = fig.add_subplot(211)
      plt.title('mean precipitation MJJAS %i BC ' % years[y],fontsize=10)
      cs = m.contourf(lon,lat,prec_avg[y,:,:],latlon=True,cmap=cm.jet,levels = np.linspace(0, 500, 30))
  
  
      ax = fig.add_subplot(212)
      plt.title('total precipitation MJJAS %i BC ' % years[y],fontsize=10)
      cs = m.contourf(lon,lat,prec_sum[y,:,:],latlon=True,cmap=cm.jet,levels = np.linspace(0, 4000, 50))
  
      pfile.savefig()
      plt.close()
  pfile.close()
  </code></pre>
  
  <p>And for the first y-step it workes fine and there is no error, just when in jumps into the loop the second time, so for y=1 it produces the error:</p>
  
  <pre><code>ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
  </code></pre>
  
  <p>in the line where I am giving the plot command : </p>
  
  <pre><code>cs=m.contourf(lon,lat,prec_avg.........
  </code></pre>
  
  <p>I also tried to define the variable <code>prec_avg</code> and <code>prec_sum</code> within in the loop, then without the first dimension and deleted the variables also at the end, with the aim to reset the variable and define it new within each loop step, But this isn't working either. The problem must be somewhere else and maybe someone can help me with this! Thanks!</p>