我不知道如何使用以下代码向我的GRIB图添加颜色条:
grib='/home/rik/hrrr/afr/vis.t20z.f00.grib2'
grbs=pygrib.open(grib)
lats, lons = grb.latlons()
map_crs = ccrs.LambertConformal(central_longitude=-100,
central_latitude=35,
standard_parallels=(30, 60))
data_crs = ccrs.PlateCarree()
fig = plt.figure(1, figsize=(14,12))
ax = plt.subplot(1, 1, 1, projection=map_crs)
ax.set_extent([-120, -75, 25, 50], data_crs)
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))
ax.add_feature(cfeature.STATES.with_scale('50m'))
ax.contourf(lons, lats, grb.values, transform=data_crs)
plt.title('Surface Visibility')
plt.colorbar(grb.values, orientation='vertical')
执行上面的代码后,我看到带有空垂直彩条的图。我想念什么?
答案 0 :(得分:0)
在调用plt.colorbar()
时,第一个参数是颜色栏应与之对应的matplotlib艺术家-在这种情况下,您要对contourf
进行颜色映射,因此您应该从此方法中获取返回值,通过它,就像这样:
cntr = ax.contourf(lons, lats, grb.values, transform=data_crs)
plt.colorbar(cntr, orientation='vertical')