MCPcopy
hub / github.com/matplotlib/matplotlib / MidpointNormalize

Class MidpointNormalize

galleries/users_explain/colors/colormapnorms.py:347–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345
346
347class MidpointNormalize(colors.Normalize):
348 def __init__(self, vmin=None, vmax=None, vcenter=None, clip=False):
349 self.vcenter = vcenter
350 super().__init__(vmin, vmax, clip)
351
352 def __call__(self, value, clip=None):
353 # I'm ignoring masked values and all kinds of edge cases to make a
354 # simple example...
355 # Note also that we must extrapolate beyond vmin/vmax
356 x, y = [self.vmin, self.vcenter, self.vmax], [0, 0.5, 1.]
357 return np.ma.masked_array(np.interp(value, x, y,
358 left=-np.inf, right=np.inf))
359
360 def inverse(self, value):
361 y, x = [self.vmin, self.vcenter, self.vmax], [0, 0.5, 1]
362 return np.interp(value, x, y, left=-np.inf, right=np.inf)
363
364
365fig, ax = plt.subplots()

Callers 1

colormapnorms.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…