background
for plotting 2-d spatial distribution of attribute, contourf , pcolormesh both choice visualization form.
due actual meaning of plotting data, want set value nearby 0 showing in white color(for example, [-0.2,0.2]); , 0 value should midpoint
from question [defining midpoint of colormap in matplotlib, tried set vmin , vmax adjust colormap.
data import
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. contourf plot
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 plot
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) i upload data here .grib2 file. if interested, can download it
my doubt
with contourf plot type, setting symmetrical
vmin,vmaxcouldn't adjust zeron midpoint of colormap. that's different pcolormesh.the same colormap
rdbu_r==> different result incontourf,pcolormesh. inpcolormeshplot, middle partof colorbar shown inwhite color. incontourfplot, white color seemed ignored.

