title: Matplotlib: use 2 datasets different length datasets to plot x and y
body: <p>I've been trying to use file gages.txt for x axis values and file data.rei for y axis values. I've run into an error because the two file are not the same length. I want to plot a separate graph for each time the <code>pestID</code> in <code>gages.txt</code> matches the Name in <code>data.rei</code>.</p>
  
  <p>Here is an excerpt of gages.txt</p>
  
  <p>gage    date    pestID  Measurement(cfd)    weight  group
  06459175    10/1/1993   devfl1  12788474.59 1.40309E-06 devflux
  06459175    11/1/1993   devfl2  12208086.39 1.40309E-06 devflux
  06459175    12/1/1993   devfl3  13559062.49 1.40309E-06 devflux
  06459175    1/1/1994    devfl4  12419465.45 1.40309E-06 devflux
  06459175    2/1/1994    devfl5  12070242.32 1.40309E-06 devflux
  06459175    3/1/1994    devfl6  14298632.14 1.40309E-06 devflux
  06459175    4/1/1994    devfl7  13348094.29 1.40309E-06 devflux
  06459175    5/1/1994    devfl8  13164766.46 1.40309E-06 devflux
  06459175    6/1/1994    devfl9  12737079.24 1.40309E-06 devflux
  06459175    7/1/1994    devfl10 12663994.86 1.40309E-06 devflux
  06459175    8/1/1994    devfl11 13164849.87 1.40309E-06 devflux
  06459200    10/1/1966   devfl253    17304667.25 1.20897E-06 devflux
  06459200    11/1/1966   devfl254    16790039.95 1.20897E-06 devflux
  06459200    12/1/1966   devfl255    13414046.27 1.20897E-06 devflux
  06459200    1/1/1967    devfl256    13146007.51 1.20897E-06 devflux
  06459200    2/1/1967    devfl257    15104020.28 1.20897E-06 devflux
  06459200    3/1/1967    devfl258    16573573.51 1.20897E-06 devflux
  06459200    4/1/1967    devfl259    18090091.13 1.20897E-06 devflux
  06459200    5/1/1967    devfl260    18112268.35 1.20897E-06 devflux
  06459200    6/1/1967    devfl261    16365348.96 1.20897E-06 devflux
  06459200    7/1/1967    devfl262    16490349.44 1.20897E-06 devflux
  06459200    8/1/1967    devfl263    16167208.44 1.20897E-06 devflux
  06459200    9/1/1967    devfl264    15875425.16 1.20897E-06 devflux
  06776500    7/1/1961    devfl6725   27784610.2  7.33613E-07 devflux
  06776500    8/1/1961    devfl6726   27008782.61 7.33613E-07 devflux
  06776500    9/1/1961    devfl6727   27727258.45 7.33613E-07 devflux
  06776500    10/1/1961   devfl6728   30051668.13 7.33613E-07 devflux
  06776500    11/1/1961   devfl6729   28593805.65 7.33613E-07 devflux
  06776500    12/1/1961   devfl6730   20188155.91 7.33613E-07 devflux
  06776500    1/1/1962    devfl6731   18106275.83 7.33613E-07 devflux
  06776500    2/1/1962    devfl6732   19852941.78 7.33613E-07 devflux
  06776500    3/1/1962    devfl6733   26060013.78 7.33613E-07 devflux</p>
  
  <p>Here is excerpt of data.rei:</p>
  
  <p>Name                 Group          Measured         Modelled         Residual         Weight
   pdwl1                pdwls          2083.620         2089.673        -6.052805        9.4067000E-04
   pdwl2                pdwls          2186.748         2199.771        -13.02284        8.9630800E-04
   pdwl3                pdwls          2150.983         2160.259        -9.275730        9.1121100E-04
   pdwl4                pdwls          2133.283         2142.970        -9.686504        9.1877100E-04
   pdwl5                pdwls          2241.741         1769.331         472.4097        8.7432100E-04
   pst_1                devwls         2191.200         2094.658         96.54200         1.000000<br>
   pst_2                devwls         2194.160         2094.070         100.0900         1.000000<br>
   pst_3                devwls         2190.790         2093.375         97.41500         1.000000<br>
   pst_4                devwls         2191.700         2092.671         99.02900         1.000000<br>
   pst_5                devwls         2188.260         2092.739         95.52100         1.000000<br>
   devfl1               devflux       1.2788475E+07    1.2199410E+07     589064.6        1.4030900E-06
   devfl2               devflux       1.2208086E+07    1.2044727E+07     163359.4        1.4030900E-06
   devfl3               devflux       1.3559062E+07    1.1423958E+07     2135104.        1.4030900E-06
   devfl4               devflux       1.2419465E+07    1.1141419E+07     1278046.        1.4030900E-06
   devfl5               devflux       1.2070242E+07    1.0925833E+07     1144409.        1.4030900E-06
   devfl10673           devflux       1.5491064E+07    1.0987895E+08   -9.4387886E+07    3.3832500E-07
   devfl10674           devflux       1.4034349E+07    1.0585104E+08   -9.1816691E+07    3.3832500E-07
   devfl10675           devflux       1.8542658E+07    1.0808722E+08   -8.9544562E+07    3.3832500E-07
   devfl10676           devflux       2.6080914E+07    1.1146742E+08   -8.5386506E+07    3.3832500E-07
   devfl10677           devflux       2.7600680E+07    1.1286638E+08   -8.5265700E+07    3.3832500E-07
   devfl10678           devflux       5.7568459E+07    1.2289897E+08   -6.5330511E+07    3.3832500E-07
   devfl10679           devflux       7.9939784E+07    1.2019735E+08   -4.0257566E+07    3.3832500E-07
   devfl10772           devflux       5.8896718E+07    1.3656509E+08   -7.7668372E+07    3.3832500E-07
   devfl10773           devflux       9.1145662E+07    1.3911792E+08   -4.7972258E+07    3.3832500E-07
   devfl10774           devflux       7.6386027E+07    1.3618379E+08   -5.9797763E+07    3.3832500E-07
   devfl10775           devflux       8.6729650E+07    1.5717141E+08   -7.0441760E+07    3.3832500E-07
   devfl10776           devflux       1.3065667E+08    1.5286262E+08   -2.2205948E+07    3.3832500E-07</p>
  
  <p>The basic loop i want to do is "if data['Name'] == gages['pestID'], then plot gages['date'] on x-axis and data['Measured'] on y axis]"</p>
  
  <p>Here is my script:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  data = np.genfromtxt('data.rei', dtype=None, names=True, skip_header=6)
  gages = np.genfromtxt('gages.txt', dtype=None, names=True, 
      delimiter=('\t'), autostrip=True, usecols=(0, 1, 2))
  
  font = {'size'   : 10,}
  
  #-----Dev BFs__________________________________
  #plt.rc('axes', color_cycle=['r'])
  #for gages['gage'] in gages:
  if gages['pestID'] == data['Name']:
      plt.scatter(gages['date'], data['Measured'],gages['date'], data['Modelled'])
      plt.legend('Measured','Modelled')
      #plt.plot([0,4000],[0,4000])
      plt.xlabel('date', fontdict=font)
      plt.ylabel('flux (cfd)', fontdict=font)
      plt.title.gages(['gage'], fontdict=font) 
      #plt.xlim(1000,4000)
      #plt.ylim(-2000,4000)
      plt.show()
  else:
      print 'no match'
  </code></pre>
  
  <p>Here is the error:</p>
  
  <pre><code>ValueError  Traceback (most recent call last)
  C:\Program Files\Enthought\Canopy\App\appdata\canopy-1.1.0.1371.win-x86_64\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
      174             else:
      175                 filename = fname
  --&gt; 176             exec compile(scripttext, filename, 'exec') in glob, loc
      177     else:
      178         def execfile(fname, *where):
  
  C:\From_LT017_old D drive\Projects\ELM\FY14\python\elm3_1-4 devFlux plot from rei.py in &lt;module&gt;()
       13 #plt.rc('axes', color_cycle=['r'])
       14 #for gages['gage'] in gages:
  ---&gt; 15 if gages['pestID'] == data['Name']:
       16     plt.scatter(gages['date'], data['Measured'],gages['date'], data['Modelled'])
       17     plt.legend('Measured','Modelled')
  
  ValueError: shape mismatch: objects cannot be broadcast to a single shape
  </code></pre>
  
  <p>I am perplexed because i thought the loop would take care of this problem.</p>