| 345 | |
| 346 | |
| 347 | class 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 | |
| 365 | fig, ax = plt.subplots() |
no outgoing calls
no test coverage detected
searching dependent graphs…