from matplotlib import colors
import numpy as np

class SaveOutput:
    def __init__(self):
        self.outputs = []

    def __call__(self, module, module_in, module_out):
        self.outputs.append(module_out)

    def clear(self):
        self.outputs = []

class MidpointNormalize(colors.Normalize):
    def __init__(self, vmin=None, vmax=None, vcenter=None, clip=False):
        self.vcenter = vcenter
        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.vcenter, self.vmax], [self.vmin, self.vcenter, self.vmax]
        return np.ma.masked_array(np.interp(value, x, y))

[((17, 8, 17, 57), 'matplotlib.colors.Normalize.__init__', 'colors.Normalize.__init__', ({(17, 34, 17, 38): 'self', (17, 40, 17, 44): 'vmin', (17, 46, 17, 50): 'vmax', (17, 52, 17, 56): 'clip'}, {}), '(self, vmin, vmax, clip)', False, 'from matplotlib import colors\n'), ((23, 34, 23, 56), 'numpy.interp', 'np.interp', ({(23, 44, 23, 49): 'value', (23, 51, 23, 52): 'x', (23, 54, 23, 55): 'y'}, {}), '(value, x, y)', True, 'import numpy as np\n')]