title: Matplotlib scattered plots inside a nested for loop
body: <p>I have 2 folders, each of them contain 2 files:</p>
  
  <pre><code>./folder_222/116.5.dat
  ./folder_222/118.1.dat
  
  ./folder_444/116.5.dat
  ./folder_444/118.1.dat  
  </code></pre>
  
  <p>(116.5 and 118.1 represent a volume)</p>
  
  <p>I would like to create a 2 row, 1 column subplot graph, where:</p>
  
  <pre><code>Upper Graph:     
       Title: V = 116.5
       Contains the plot of:
       folder_222/116.5.dat
       folder_444/116.5.dat
  
  Lower Graph: 
       Title: V = 118.1    
       Contains the plot of:
       folder_222/118.1.dat
       folder_444/118.1.dat
  </code></pre>
  
  <p>The best way I thought about is the following:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import os
  
  # Folders, files and volumes:
  folder_222 = './folder_222'
  folder_444 = './folder_444'
  
  files_222 = ["116.5.dat",\
  "118.1.dat"]
  
  files_444 = ["116.5.dat",\
  "118.1.dat"]
  
  vols = ["116.5",\
  "118.1"]
  
  fig = plt.figure()
  
  # Generation of the subplots, and the title:    
  for indx_vols in range(1, len(vols)+1):
      print '    indx_vols = ', indx_vols
      ax = fig.add_subplot(len(vols), 1, indx_vols)
      ax.set_title('V = ' + vols[indx_vols-1], fontsize=10) 
  
      # For a given subplot, now plot x and y:
      for indx_files in range(len(vols)):
  
          print 'indx_files = ', indx_files
          x_222, y_222 = np.loadtxt(os.path.join(folder_222, files_222[indx_files]), skiprows = 1).T
          x_444, y_444 = np.loadtxt(os.path.join(folder_444, files_444[indx_files]), skiprows = 1).T
          print 'y_222 = ', y_222, 'x_222 = ', x_222
          print 'y_444 = ', y_444, 'x_444 = ', x_444
          ax.scatter(x_222, y_222, color='k', marker='o', label='222')
          ax.scatter(x_444, y_444, color='m', marker='o', label='444')
  </code></pre>
  
  <p>If you run the program with all these print statements, is possible to see that that the program is doing what expected:</p>
  
  <pre><code>    indx_vols =  1
  indx_files =  0
  y_222 =  [ 1086.  2328.  3633.  3387.  1278.] x_222 =  [  89.  629.  694.  785.  882.]
  y_444 =  [ 2262.  3876.  1119.  4338.  2817.] x_444 =  [  753.  1291.   372.  1445.   938.]
  indx_files =  1
  y_222 =  [ 1353.   903.  4695.   429.  4641.] x_222 =  [  450.   300.  1564.   142.  1546.]
  y_444 =  [ 3102.  1335.    57.  1962.  2958.] x_444 =  [ 1033.   444.    18.   653.   985.]
      indx_vols =  2
  indx_files =  0
  y_222 =  [ 1086.  2328.  3633.  3387.  1278.] x_222 =  [  89.  629.  694.  785.  882.]
  y_444 =  [ 2262.  3876.  1119.  4338.  2817.] x_444 =  [  753.  1291.   372.  1445.   938.]
  indx_files =  1
  y_222 =  [ 1353.   903.  4695.   429.  4641.] x_222 =  [  450.   300.  1564.   142.  1546.]
  y_444 =  [ 3102.  1335.    57.  1962.  2958.] x_444 =  [ 1033.   444.    18.   653.   985.]
  </code></pre>
  
  <p>However, there is no difference between both subpots:</p>
  
  <p><a href="https://i.stack.imgur.com/tpt3l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tpt3l.png" alt="enter image description here"></a></p>
  
  <p>It is like if only one volume-data set was considered. </p>
  
  <p>I would appreciate if you could help me</p>
  
  <p>Here the files to run the code:</p>
  
  <pre><code>./folder_222/116.5.dat:
  
  # x   y
  89   1086 
  629  2328
  694  3633
  785  3387
  882  1278
  
  ./folder_222/118.1.dat:
  
  # x  y
  450  1353
  300  903
  1564 4695
  142  429
  1546 4641
  
  ./folder_444/116.5.dat:
  
  # x   y
  753  2262
  1291 3876
  372  1119
  1445 4338
  938  2817
  
  ./folder_444/118.1.dat:
  
  # x  y
  1033  3102
  444   1335
  18    57
  653   1962
  985   2958
  </code></pre>