def __init__(self, colors, N, stops=None): # store stops self.stops = stops # set colors self.set_color(colors) # initialize Colormap.__init__(self, "test", N)
def __init__(self, colors: Sequence, N: int, stops=None): """ initialize with the given colors and stops """ # store stops self.stops = stops # set colors self.set_color(colors) # initialize Colormap.__init__(self, "test", N)
def __init__(self, accels, max_accel=None, min_accel=None): self.accels = accels self.points = len(self.accels) if min_accel is not None: self.min_accel = min_accel else: self.min_accel = np.min(accels) if max_accel is not None: self.max_accel = max_accel else: self.max_accel = np.max(accels) Colormap.__init__(self, None, 255)
def __init__(self, source, name='Variable'): self.name = None # new VariableColormap object self.bad_set = False self.set_source(source) self.monochrome = False Colormap.__init__(self, name, self.worklut.shape[0]-3) self.canvases = {} self.frames = set() self.slope = 1.0 self.shift = 0.0 self.invrt = 1.0 self.scale = 'LINEAR' self.auto = True
def __init__(self, cmap): """ Make a colormap dynamic with respect to a hinge point. Dynamic colormaps are stretched to the ``[vmin, vmax]`` range, by separately scaling the lower part of the colormap (v < ``hinge``) and the upper part (v > ``hinge``). For instance, a colormap with v range `[-1, 1]` and hinge at `0` with `min_color` at `-1`, `hinge_color` and the ``hinge``, and `max_color` at `1`, can be dynamically scaled to ``[-10, 5]`` with `min_color` at `-10`, `hinge_color` and the ``hinge``, and `max_color` at `5`:: <|min_color-----------hinge_color-----------max_color|> -1 0 1 \ \ \ \ <|min_color-----------------hinge_color-----max_color|> -10 0 5 See Also -------- DynamicColormap.set_range Scale the colormap to a new range, keeping, or overriding the hinge point. """ self.monochrome = False Colormap.__init__(self, cmap.name, cmap.N) try: self.values = cmap.values except AttributeError: self.values = np.linspace(-1, 1, self.N) self._vmin = self.values[0] try: self._hinge = cmap.hinge except AttributeError: self._hinge = 0 self._vmax = self.values[-1] try: self.colors = cmap.colors except AttributeError: self.colors = cmap(self.values) self.set_range(self.vmin, self.vmax, self.hinge) self._lut = cmap._lut self._isinit = True self._set_extremes()
def __init__(self, source, name='Variable'): self.name = None # new VariableColormap object self.bad_set = False self.set_source(source) self.monochrome = False Colormap.__init__(self, name, self.worklut.shape[0]-3) self.canvases = {} self.frames = set() self.slope = 1.0 self.shift = 0.0 self.invrt = 1.0 self.scale = 'LINEAR' self.auto = True self.callback = None
def __init__(self, name, color, min_alpha=0.0, max_alpha=1.0, N=256): Colormap.__init__(self, name, N) self._color = color self._min_alpha = min_alpha self._max_alpha = max_alpha
def __init__(self, cmap, vmin=0, vmax=1): if not has_mpl: raise ImportError("Could not import all matplotlib dependencies!") if isinstance(cmap, str): Colormap.__init__(self, cmap, vmin, vmax) cmap = mpl_get_cmap(cmap) else: try: name = str(cmap.name) except: raise ValueError("The argument 'cmap' is of wrong type!") Colormap.__init__(self, name, vmin, vmax) # Obtain table to convert to .cpt: if 'colors' in cmap.__dict__.keys(): if isinstance(cmap.colors, list): N = len(cmap.colors) elif isinstance(cmap.colors, np.ndarray): N = cmap.colors.shape[0] else: raise ValueError("Data type not understood: " + str(type(cmap.colors))) self.cpt_table = np.zeros((N, 4)) self.cpt_table[:, 1:4] = cmap.colors self.cpt_table[:, 0] = np.linspace(0, 1, N) elif '_segmentdata' in cmap.__dict__.keys(): # Obtain the segments for all three colors: segs = [ np.array(cmap._segmentdata['red']), np.array(cmap._segmentdata['green']), np.array(cmap._segmentdata['blue']) ] changes = set([seg[0] for seg in segs[0]]) \ | set([seg[0] for seg in segs[1]]) \ | set([seg[0] for seg in segs[2]]) changes = np.sort(np.array(list(changes)))[1:] colors = [] colors += [[0, segs[0][0, 1], segs[1][0, 1], segs[2][0, 1]]] for x in changes: c0 = [0, 0, 0] c1 = [0, 0, 0] for k in range(3): id_ = np.argwhere(segs[k][:, 0] < x)[-1] if id_ < len(segs[k]): if segs[k][id_ + 1, 0] == x: # Red value changes at x: c0[k] = segs[k][id_ + 1, 1][0] c1[k] = segs[k][id_ + 1, 2][0] else: # Red value does not change at x. Interpolate linearly: x0 = segs[k][id_, 0][0] v0 = segs[k][id_, 2][0] x1 = segs[k][id_ + 1, 0][0] v1 = segs[k][id_ + 1, 1][0] c0[k] = (x - x0) / (x1 - x0) * v0 + (x1 - x) / ( x1 - x0) * v1 c1[k] = c0[k] colors += [[x, c0[0], c0[1], c0[2]]] if c0[0] != c1[0] or c0[0] != c1[0] or c0[0] != c1[0]: colors += [[x, c1[0], c1[1], c1[2]]] self.cpt_table = np.array(colors)
def __init__(self, name, color, min_alpha = 0.0, max_alpha = 1.0, N=256): Colormap.__init__(self, name, N) self._color = color self._min_alpha = min_alpha self._max_alpha = max_alpha
def __init__(self, name, color, N=256): Colormap.__init__(self, name, N) self.color = colorConverter.to_rgb(color)