Here is my question.
The contourf
plot showing below represent the vertical velocity of atmospheric transport in the place of interests.
What I want to do is to set the velocity nearby 0.0 corresponding to the color white.
So, I have tried the code below to achieve that.
num_levels = 20
vmin, vmax = data.min(), data.max() ## data is the 2-d array I want to show
midpoint = 0
levels = np.linspace(-1, +1, num_levels)
midp = np.mean(np.c_[levels[:-1], levels[1:]], axis=1)
vals = np.interp(midp, [vmin, midpoint, vmax], [0, 0.5, 1])
colors = plt.cm.RdBu_r(vals)
cmap, norm = from_levels_and_colors(levels, colors)
cs = plt.contourf(x,y,data,cmap=cmap, norm=norm, interpolation='none')
The result shows like this:
Velocity == 0 became the midpoint of the colorbar as I would like to. But the color range of the second plot seems to be shrink. Then, the information on the second plot became unclear. How to shift the midpoint of the colorbar without changing the color range?
Any advice would be appreciate!