matplotlib确实在底图上绘制数据

时间:2016-01-23 00:34:11

标签: python matplotlib-basemap

我正在尝试使用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()

终端输出显示数据&#39;数据的可用性。变量: -

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 个答案:

答案 0 :(得分:0)

我使用错误的编码是不好的。应该是

x, y = m(lons, lats)

现在有效。