5

背景

用于绘制某些属性的二维空间分布,作为可视contourfpcolormesh形式都是不错的选择。

由于绘图数据的实际含义,我想将零附近的值设置为白色(例如,[-0.2,0.2]);零值应该是中点

从问题 [ Defining the midpoint of a colormap in matplotlib,我尝试设置vminvmax调整颜色图。

数据导入

import pygrib
grib='fnl_20141110_12_00.grib2';
grbs=pygrib.open(grib)
grb = grbs.select(name='Vertical velocity')[8]#Vertical velocity
data=grb.values
lat,lon = grb.latlons()

1. 等高线图

m = Basemap(llcrnrlon=110,llcrnrlat=34,urcrnrlon=122,urcrnrlat=44,projection='mill')
fig=plt.figure(figsize=(8,4))
ax1 = plt.subplot(121)
x, y = m(lon, lat)
cs = m.contourf(x,y,data,cmap=plt.cm.RdBu)

cb = m.colorbar(cs,"bottom", size="5%", pad="8%")
ax1.set_title("Original",fontsize = 15)

ax2 = plt.subplot(122)
cs = m.contourf(x,y,data,cmap=plt.cm.RdBu,vmin = -1.8,vmax =1.8)
cb = m.colorbar(cs,"bottom", size="5%", pad="8%")
ax2.set_title("symmetrical vmin & vmax",fontsize = 15)

在此处输入图像描述

2. Pcolormesh 图

m = Basemap(llcrnrlon=110,llcrnrlat=34,urcrnrlon=122,urcrnrlat=44,projection='mill')
fig=plt.figure(figsize=(8,4))
ax1 = plt.subplot(121)
cs = m.pcolormesh(x,y,data,cmap=plt.cm.RdBu)
cb = m.colorbar(cs,"bottom", size="5%", pad="8%")
ax1.set_title("Original",fontsize = 15)

ax2 = plt.subplot(122)
cs = m.pcolormesh(x,y,data,cmap=plt.cm.RdBu,vmin = -1.8,vmax =1.8)
cb = m.colorbar(cs,"bottom", size="5%", pad="8%")
ax2.set_title("symmetrical vmin & vmax",fontsize = 15)

在此处输入图像描述

我在这里将数据作为 .grib2 文件上传。有兴趣的可以下载

我的怀疑

  1. 使用contourf绘图类型,设置对称vminvmax无法将 zeron 调整到颜色图的中点。这与pcolormesh不同。

  2. 相同的颜色图RdBu_r==> 不同的结果在contourf和中pcolormesh。在pcolormesh图中,颜色条的中间部分显示在 中white color。但在contourf情节中,白色似乎被忽略了。

4

0 回答 0