How to use the napari._vispy.color.colormap.Colormap function in napari

To help you get started, we’ve selected a few napari examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github napari / napari / napari / _vispy / color / colormap.py View on Github external
# Some colormap presets
    autumn=Colormap([(1., 0., 0., 1.), (1., 1., 0., 1.)]),
    blues=Colormap([(1., 1., 1., 1.), (0., 0., 1., 1.)]),
    cool=Colormap([(0., 1., 1., 1.), (1., 0., 1., 1.)]),
    greens=Colormap([(1., 1., 1., 1.), (0., 1., 0., 1.)]),
    reds=Colormap([(1., 1., 1., 1.), (1., 0., 0., 1.)]),
    spring=Colormap([(1., 0., 1., 1.), (1., 1., 0., 1.)]),
    summer=Colormap([(0., .5, .4, 1.), (1., 1., .4, 1.)]),
    fire=_Fire(),
    grays=_Grays(),
    hot=_Hot(),
    ice=_Ice(),
    winter=_Winter(),
    light_blues=_SingleHue(),
    orange=_SingleHue(hue=35),
    viridis=Colormap(ColorArray(_viridis_data)),
    # Diverging presets
    coolwarm=Colormap(ColorArray(
        [
            (226, 0.59, 0.92), (222, 0.44, 0.99), (218, 0.26, 0.97),
            (30, 0.01, 0.87),
            (20, 0.3, 0.96), (15, 0.5, 0.95), (8, 0.66, 0.86)
        ],
        color_space="hsv"
    )),
    PuGr=_Diverging(145, 280, 0.85, 0.30),
    GrBu=_Diverging(255, 133, 0.75, 0.6),
    GrBu_d=_Diverging(255, 133, 0.75, 0.6, "dark"),
    RdBu=_Diverging(220, 20, 0.75, 0.5),

    # Configurable colormaps
    cubehelix=CubeHelixColormap,
github napari / napari / napari / _vispy / color / colormap.py View on Github external
[0.935904, 0.898570, 0.108131],
                 [0.945636, 0.899815, 0.112838],
                 [0.955300, 0.901065, 0.118128],
                 [0.964894, 0.902323, 0.123941],
                 [0.974417, 0.903590, 0.130215],
                 [0.983868, 0.904867, 0.136897],
                 [0.993248, 0.906157, 0.143936]]


_colormaps = dict(
    # Some colormap presets
    autumn=Colormap([(1., 0., 0., 1.), (1., 1., 0., 1.)]),
    blues=Colormap([(1., 1., 1., 1.), (0., 0., 1., 1.)]),
    cool=Colormap([(0., 1., 1., 1.), (1., 0., 1., 1.)]),
    greens=Colormap([(1., 1., 1., 1.), (0., 1., 0., 1.)]),
    reds=Colormap([(1., 1., 1., 1.), (1., 0., 0., 1.)]),
    spring=Colormap([(1., 0., 1., 1.), (1., 1., 0., 1.)]),
    summer=Colormap([(0., .5, .4, 1.), (1., 1., .4, 1.)]),
    fire=_Fire(),
    grays=_Grays(),
    hot=_Hot(),
    ice=_Ice(),
    winter=_Winter(),
    light_blues=_SingleHue(),
    orange=_SingleHue(hue=35),
    viridis=Colormap(ColorArray(_viridis_data)),
    # Diverging presets
    coolwarm=Colormap(ColorArray(
        [
            (226, 0.59, 0.92), (222, 0.44, 0.99), (218, 0.26, 0.97),
            (30, 0.01, 0.87),
            (20, 0.3, 0.96), (15, 0.5, 0.95), (8, 0.66, 0.86)
github napari / napari / napari / _vispy / color / colormap.py View on Github external
[0.926106, 0.897330, 0.104071],
                 [0.935904, 0.898570, 0.108131],
                 [0.945636, 0.899815, 0.112838],
                 [0.955300, 0.901065, 0.118128],
                 [0.964894, 0.902323, 0.123941],
                 [0.974417, 0.903590, 0.130215],
                 [0.983868, 0.904867, 0.136897],
                 [0.993248, 0.906157, 0.143936]]


_colormaps = dict(
    # Some colormap presets
    autumn=Colormap([(1., 0., 0., 1.), (1., 1., 0., 1.)]),
    blues=Colormap([(1., 1., 1., 1.), (0., 0., 1., 1.)]),
    cool=Colormap([(0., 1., 1., 1.), (1., 0., 1., 1.)]),
    greens=Colormap([(1., 1., 1., 1.), (0., 1., 0., 1.)]),
    reds=Colormap([(1., 1., 1., 1.), (1., 0., 0., 1.)]),
    spring=Colormap([(1., 0., 1., 1.), (1., 1., 0., 1.)]),
    summer=Colormap([(0., .5, .4, 1.), (1., 1., .4, 1.)]),
    fire=_Fire(),
    grays=_Grays(),
    hot=_Hot(),
    ice=_Ice(),
    winter=_Winter(),
    light_blues=_SingleHue(),
    orange=_SingleHue(hue=35),
    viridis=Colormap(ColorArray(_viridis_data)),
    # Diverging presets
    coolwarm=Colormap(ColorArray(
        [
            (226, 0.59, 0.92), (222, 0.44, 0.99), (218, 0.26, 0.97),
            (30, 0.01, 0.87),
github napari / napari / napari / _vispy / color / colormap.py View on Github external
def __init__(self, h_pos=20, h_neg=250, saturation=1.0, value=0.7,
                 center="light"):
        saturation *= 99
        value *= 99

        start = husl_to_rgb(h_neg, saturation, value)
        mid = ((0.133, 0.133, 0.133) if center == "dark" else
               (0.92, 0.92, 0.92))
        end = husl_to_rgb(h_pos, saturation, value)

        colors = ColorArray([start, mid, end])

        super(_Diverging, self).__init__(colors)


class _RedYellowBlueCyan(Colormap):
    """A colormap which is goes red-yellow positive and blue-cyan negative

    Parameters
    ---------
    limits : array-like, optional
        The limits for the fully transparent, opaque red, and yellow points.
    """

    def __init__(self, limits=(0.33, 0.66, 1.0)):
        limits = np.array(limits, float).ravel()
        if len(limits) != 3:
            raise ValueError('limits must have 3 values')
        if (np.diff(limits) < 0).any() or (limits <= 0).any():
            raise ValueError('limits must be strictly increasing and positive')
        controls = np.array([-limits[2], -limits[1], -limits[0],
                             limits[0], limits[1], limits[2]])
github napari / napari / napari / _vispy / color / colormap.py View on Github external
def __init__(self, colors, controls=None, interpolation='linear'):
        self.interpolation = interpolation
        ncontrols = self._ncontrols(len(colors))
        # Default controls.
        if controls is None:
            controls = _default_controls(ncontrols)
        assert len(controls) == ncontrols
        self._controls = np.array(controls, dtype=np.float32)
        # use texture map for luminance to RGBA conversion
        self.texture_map_data = np.zeros((LUT_len, 1, 4), dtype=np.float32)
        self.glsl_map = self._glsl_map_generator(self._controls, colors,
                                                 self.texture_map_data)
        super(Colormap, self).__init__(colors)
github napari / napari / napari / _vispy / color / colormap.py View on Github external
[0.906311, 0.894855, 0.098125],
                 [0.916242, 0.896091, 0.100717],
                 [0.926106, 0.897330, 0.104071],
                 [0.935904, 0.898570, 0.108131],
                 [0.945636, 0.899815, 0.112838],
                 [0.955300, 0.901065, 0.118128],
                 [0.964894, 0.902323, 0.123941],
                 [0.974417, 0.903590, 0.130215],
                 [0.983868, 0.904867, 0.136897],
                 [0.993248, 0.906157, 0.143936]]


_colormaps = dict(
    # Some colormap presets
    autumn=Colormap([(1., 0., 0., 1.), (1., 1., 0., 1.)]),
    blues=Colormap([(1., 1., 1., 1.), (0., 0., 1., 1.)]),
    cool=Colormap([(0., 1., 1., 1.), (1., 0., 1., 1.)]),
    greens=Colormap([(1., 1., 1., 1.), (0., 1., 0., 1.)]),
    reds=Colormap([(1., 1., 1., 1.), (1., 0., 0., 1.)]),
    spring=Colormap([(1., 0., 1., 1.), (1., 1., 0., 1.)]),
    summer=Colormap([(0., .5, .4, 1.), (1., 1., .4, 1.)]),
    fire=_Fire(),
    grays=_Grays(),
    hot=_Hot(),
    ice=_Ice(),
    winter=_Winter(),
    light_blues=_SingleHue(),
    orange=_SingleHue(hue=35),
    viridis=Colormap(ColorArray(_viridis_data)),
    # Diverging presets
    coolwarm=Colormap(ColorArray(
        [
github napari / napari / napari / _vispy / color / colormap.py View on Github external
"""Return a texture2D object for LUT after its value is set."""
        if self.texture_map_data is not None:
            interpolation_mode = 'linear' \
                if(str(self.interpolation) == 'linear') \
                else 'nearest'
            texture_LUT = \
                vispy.gloo.Texture2D(np.zeros(self.texture_map_data.shape),
                                     interpolation=interpolation_mode)
            texture_LUT.set_data(self.texture_map_data,
                                 offset=None, copy=True)
        else:
            texture_LUT = None
        return texture_LUT


class MatplotlibColormap(Colormap):
    """Use matplotlib colormaps if installed.

    Parameters
    ----------
    name : string
        Name of the colormap.
    """

    def __init__(self, name):
        from matplotlib.cm import ScalarMappable

        vec = ScalarMappable(cmap=name).to_rgba(np.arange(LUT_len))
        Colormap.__init__(self, vec)


class CubeHelixColormap(Colormap):
github napari / napari / napari / _vispy / color / colormap.py View on Github external
[0.916242, 0.896091, 0.100717],
                 [0.926106, 0.897330, 0.104071],
                 [0.935904, 0.898570, 0.108131],
                 [0.945636, 0.899815, 0.112838],
                 [0.955300, 0.901065, 0.118128],
                 [0.964894, 0.902323, 0.123941],
                 [0.974417, 0.903590, 0.130215],
                 [0.983868, 0.904867, 0.136897],
                 [0.993248, 0.906157, 0.143936]]


_colormaps = dict(
    # Some colormap presets
    autumn=Colormap([(1., 0., 0., 1.), (1., 1., 0., 1.)]),
    blues=Colormap([(1., 1., 1., 1.), (0., 0., 1., 1.)]),
    cool=Colormap([(0., 1., 1., 1.), (1., 0., 1., 1.)]),
    greens=Colormap([(1., 1., 1., 1.), (0., 1., 0., 1.)]),
    reds=Colormap([(1., 1., 1., 1.), (1., 0., 0., 1.)]),
    spring=Colormap([(1., 0., 1., 1.), (1., 1., 0., 1.)]),
    summer=Colormap([(0., .5, .4, 1.), (1., 1., .4, 1.)]),
    fire=_Fire(),
    grays=_Grays(),
    hot=_Hot(),
    ice=_Ice(),
    winter=_Winter(),
    light_blues=_SingleHue(),
    orange=_SingleHue(hue=35),
    viridis=Colormap(ColorArray(_viridis_data)),
    # Diverging presets
    coolwarm=Colormap(ColorArray(
        [
            (226, 0.59, 0.92), (222, 0.44, 0.99), (218, 0.26, 0.97),
github napari / napari / napari / _vispy / color / colormap.py View on Github external
[0.955300, 0.901065, 0.118128],
                 [0.964894, 0.902323, 0.123941],
                 [0.974417, 0.903590, 0.130215],
                 [0.983868, 0.904867, 0.136897],
                 [0.993248, 0.906157, 0.143936]]


_colormaps = dict(
    # Some colormap presets
    autumn=Colormap([(1., 0., 0., 1.), (1., 1., 0., 1.)]),
    blues=Colormap([(1., 1., 1., 1.), (0., 0., 1., 1.)]),
    cool=Colormap([(0., 1., 1., 1.), (1., 0., 1., 1.)]),
    greens=Colormap([(1., 1., 1., 1.), (0., 1., 0., 1.)]),
    reds=Colormap([(1., 1., 1., 1.), (1., 0., 0., 1.)]),
    spring=Colormap([(1., 0., 1., 1.), (1., 1., 0., 1.)]),
    summer=Colormap([(0., .5, .4, 1.), (1., 1., .4, 1.)]),
    fire=_Fire(),
    grays=_Grays(),
    hot=_Hot(),
    ice=_Ice(),
    winter=_Winter(),
    light_blues=_SingleHue(),
    orange=_SingleHue(hue=35),
    viridis=Colormap(ColorArray(_viridis_data)),
    # Diverging presets
    coolwarm=Colormap(ColorArray(
        [
            (226, 0.59, 0.92), (222, 0.44, 0.99), (218, 0.26, 0.97),
            (30, 0.01, 0.87),
            (20, 0.3, 0.96), (15, 0.5, 0.95), (8, 0.66, 0.86)
        ],
        color_space="hsv"
github napari / napari / napari / _vispy / color / colormap.py View on Github external
def __init__(self, name):
        from matplotlib.cm import ScalarMappable

        vec = ScalarMappable(cmap=name).to_rgba(np.arange(LUT_len))
        Colormap.__init__(self, vec)