I would like to plot with diverging colors centered at 0 (red for postive values and blue for negative). I tried normalizing the data with 0 as midpoint as suggested here
import matplotlib.colors as colors
import numpy as np
class MidpointNormalize(colors.Normalize):
def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False):
self.midpoint = midpoint
colors.Normalize.__init__(self, vmin, vmax, clip)
def __call__(self, value, clip=None):
# I'm ignoring masked values and all kinds of edge cases to make a
# simple example...
x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1]
return np.ma.masked_array(np.interp(value, x, y))
minzz = -4
maxzz = 1.5
plt.contourf(x, y, z, cmap='RdBu_r', norm=MidpointNormalize(midpoint=0), vmin=minzz, vmax=maxzz)
plt.xticks()
plt.colorbar()
and I get this
It does not really follow the -4 to 1.5 range and how do I also increase the intervals especially to highlight more positive values.

