代码之家  ›  专栏  ›  技术社区  ›  sundar_ima

matplotlib不在basemap上绘制数据

  •  0
  • sundar_ima  · 技术社区  · 10 年前

    我正在尝试使用pygrib从GFS数据绘制一个简单的温度图。我使用了以下链接中的示例:-

    http://jswhit.github.io/pygrib/docs/index.html http://polar.ncep.noaa.gov/waves/examples/usingpython.shtml

    下面是我要做的示例代码:-

    import pygrib
    import matplotlib.pyplot as plt
    from mpl_toolkits.basemap import Basemap
    import numpy as np
    
    grib = 'data/gfs.t00z.pgrb2f00'
    grbs = pygrib.open(grib)
    
    grbs.seek(0)
    grb = grbs.select(name='Temperature')[0]
    data, lats, lons = grb.data(lat1=0,lat2=35,lon1=60,lon2=100)
    print data  # <<--- This has some values but not plotted in the map.
    m = Basemap(projection='merc', llcrnrlat=0, urcrnrlat=35,\
                    llcrnrlon=60, urcrnrlon=100, resolution='c')
    
    x, y = m(lats, lons)
    m.drawcoastlines()
    cs = m.pcolor(x, y, np.squeeze(data))
    m.colorbar(cs, location='bottom', pad="10%")
    plt.title('Simple temperature plot from GRiB')
    plt.show()
    

    终端输出显示“data”变量的数据可用性:-

    python2.7 grib_plot.py 
    [[ 225.8  225.8  225.8 ...,  225.9  225.8  225.7]
     [ 225.7  225.7  225.6 ...,  225.8  225.8  225.7]
     [ 225.6  225.6  225.5 ...,  225.8  225.8  225.8]
     ..., 
     [ 229.1  229.1  229.1 ...,  231.1  230.8  230.6]
     [ 228.3  228.5  228.8 ...,  231.3  230.7  230.5]
     [ 227.4  227.8  228.3 ...,  231.6  231.1  230.8]]
    

    然而,所得图像没有显示温度的绘图

    sample grib data temp plot

    感谢为解决该问题提供的任何帮助。

    1 回复  |  直到 10 年前
        1
  •  0
  •   sundar_ima    10 年前

    我的错是我使用了错误的编码。它应该是

    x, y = m(lons, lats)

    它现在起作用了。