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, 'matplotlib.colors.Normalize.__init__', 'colors.Normalize.__init__', False, 'from matplotlib import colors\n'), (23, 'numpy.interp', 'np.interp', True, 'import numpy as np\n')]