使用来自2个数据集的数据绘制多个图形

时间:2013-12-12 22:55:33

标签: python numpy matplotlib plot genfromtxt

我有一个名为'data.rei'的数据集,另一个叫做'gages.txt'。 'data.rei'包含数据,'gages.txt'包含我想要与数据链接的位置ID信息和日期/时间。我想绘制这些,每个位置1个图表,包括x轴上的日期和y轴上的测量和建模值。

data.rei的格式如下:

 MODEL OUTPUTS AT END OF OPTIMISATION ITERATION NO.   0:-

 Note that weights have been adjusted in accordance with regularisation target objective function.

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    
 pst_2                devwls         2194.160         2094.070         100.0900         1.000000    
 pst_3                devwls         2190.790         2093.375         97.41500         1.000000    
 pst_4                devwls         2191.700         2092.671         99.02900         1.000000    
 pst_5                devwls         2188.260         2092.739         95.52100         1.000000   
 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

gages.txt如下:

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
06459200    5/1/1968    devfl272    17295163.25 1.20897E-06 devflux
06459200    6/1/1968    devfl273    17266053.57 1.20897E-06 devflux
06459200    7/1/1968    devfl274    16519279.99 1.20897E-06 devflux
06459200    8/1/1968    devfl275    15647156.65 1.20897E-06 devflux
06459200    9/1/1968    devfl276    17767727.81 1.20897E-06 devflux

到目前为止,这是我的脚本:

import numpy as np
import matplotlib.pyplot as plt

data = np.genfromtxt('elm3_1-4 - Copy.rei', dtype=None, names=True, skip_header=6)
gages = np.genfromtxt('elmph3_dev_gages_28may2013.txt', dtype=None, names=True)

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('Measured (ft)', fontdict=font)
        plt.ylabel('Modelled (ft)', fontdict=font)
        plt.title.gages(['gage'], fontdict=font) 
        #plt.xlim(1000,4000)
        #plt.ylim(-2000,4000)
        plt.show()

但是,我收到错误消息:

%run "C:/From_LT017_old D drive/Projects/ELM/FY14/python/elm3_1-4 devFlux plot from rei.py"
---------------------------------------------------------------------------
OverflowError                             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
--> 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 <module>()
      5 
      6 data = np.genfromtxt('elm3_1-4 - Copy.rei', dtype=None, names=True, skip_header=6)
----> 7 gages = np.genfromtxt('elmph3_dev_gages_28may2013.txt', dtype=None, names=True)
      8 
      9 font = {'size'   : 10,}

C:\Users\jtraylor\AppData\Local\Enthought\Canopy\User\lib\site-packages\numpy\lib\npyio.pyc in genfromtxt(fname, dtype, comments, delimiter, skiprows, skip_header, skip_footer, converters, missing, missing_values, filling_values, usecols, names, excludelist, deletechars, replace_space, autostrip, case_sensitive, defaultfmt, unpack, usemask, loose, invalid_raise)
   1689             ddtype = zip(names, column_types)
   1690             mdtype = zip(names, [np.bool] * len(column_types))
-> 1691         output = np.array(data, dtype=ddtype)
   1692         if usemask:
   1693             outputmask = np.array(masks, dtype=mdtype)

OverflowError: Python int too large to convert to C long

1 个答案:

答案 0 :(得分:1)

这似乎有效

gages = np.genfromtxt('gages.txt', dtype=None, names=True, delimiter=('\t'))