数据不适合底图

问题描述

当我尝试使用Grib文件中的底图绘制数据时,该地图不适合所绘制的数据。我在下面发布了代码,并在其下面发布了指向输出图像的链接。我认为投影类型可能是问题。 我还尝试使投影圆柱体化,同时保持其余代码不变,但是这也不起作用(尽管看起来更好一点),我也为此发布了指向输出图像的链接。也许这有助于可视化哪些投影将正确地适合数据? 关于您认为可能出错的任何想法将不胜感激。

from pprint import pprint
import pygrib
from mpl_toolkits.basemap import Basemap
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from ncepgrib2 import Grib2Decode


file = 'hrrr.t00z.wrfsfcf00.grib2'
gr = pygrib.open(file)


msg = gr[32] #Temperature values in Kelvin
#print(Grib2Decode(msg.tostring(),gribmsg=True))#Similar to printing all info for netCDF file
Temp = msg.values

lat,lon = msg.latlons()

m=Basemap(projection='lcc',llcrnrlon=lon.min(),\
  urcrnrlon=lon.max(),llcrnrlat=lat.min(),urcrnrlat=lat.max(),\
  lat_0 = float(msg['latitudeOfFirstGridPointIndegrees']),lon_0 =float(msg['longitudeOfFirstGridPointIndegrees']),resolution='c')

x,y = m(lon,lat)


                                                                                                                                                                                                                                                                                                                                                                                          #m = Basemap(width=11297120.0,height=8959788.0,#           resolution='c',projection='lcc',\
#            lat_ts=40,lat_0=lat_0,lon_0=lon_0)



fig = plt.figure(figsize = (18.6,10.5))
cs = m.pcolormesh(x,y,(Temp-273.15)*9/5 +32,cmap = plt.cm.jet)
m.drawcoastlines()
m.drawstates()
m.drawcountries()
plt.colorbar(cs,orientation='vertical')
plt.title('Temperature F')
plt.savefig('plot')
plt.show()                                                                                           

Image of output using lcc projection Image of output using cylindrical projection Link to HRRR data containing Grib file. All are in the exact same format,projection,etc... so you could download any one of them and get the same results (just different Temperature values)

解决方法

有多种方法可以解决您的问题:

  1. 设置xlim和ylim,这是最简单的方法:
Slider
  1. 使用cfgrib + xarray直接从xarray对象进行绘图

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...