在不规则形状上生成pcolormesh数据

时间:2019-06-04 21:10:25

标签: python matplotlib-basemap

我正在尝试在加利福尼亚地图上生成热图(从字面上讲,因为我正在尝试绘制温度数据)。我正在使用底图,有一种方法可以在我的小规模测试中使用,除了我要创建经纬度坐标的矩形集,而且当我按比例放大到整个状态时,都会遇到问题,因为状态是不是矩形。

要澄清一下,这里的挑战是我有来自不规则间隔的测量站的数据,因此我需要创建一个数据网格以实际馈入pcolormesh。如果我通过在两个linspace上使用np.meshgrid创建均匀间隔的点的网格,则会得到一个矩形空间,在加利福尼亚州的边界上运行。您可以通过向pcolormesh喂入边界内的一组点来欺骗pcolormesh,但如果它们的排列不正确(x和y值在两个方向上都严格增加),pcolormesh会感到困惑,并且不确定如何填写点之间的空间。

例如,我在加利福尼亚州内发现了一些经纬度的点

#collection of lon/lat points
lon = np.array(sample_lat_long['0'])
lat = np.array(sample_lat_long['1'])

#arranged into the sort of 2d shape pcolormesh wants
lon = lon.reshape(30,30)
lat = lat.reshape(30,30)

#I attach the appropriate estimated temperature with this function
#for every point
z = np.zeros((30,30))
for i in range(0,30):
    for j in range(0,30):
        z[i][j] = near_temp(lon[i][j],lat[i][j])

#I know that pcolormesh will match up the z with the correct lon/lats
#This draws the map
fig = plt.figure(figsize=(10,10))
map = Basemap(projection='lcc', lat_0=38.3004, lon_0=-119.4179, width=1000000, height=1000000)


map.drawstates()
map.pcolormesh(lon, lat, z, latlon=True, cmap='RdBu_r')
plt.clim(dec_31[1:].min(),dec_31[1:].max())
plt.colorbar()

但是结果很古怪,因为pcolormesh无法正确连接点。有没有一种合理的方法可以将底图的点均匀分布/井井有条,形成不规则形状?

0 个答案:

没有答案
相关问题