How to use the silx.gui.colors.Colormap function in silx

To help you get started, we’ve selected a few silx 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 silx-kit / pyFAI / pyFAI / gui / dialog / Detector3dDialog.py View on Github external
pixelValues = pixelValues.astype(numpy.float)
            pixelValues[mask != 0] = numpy.float("nan")

        values = numpy.empty(shape=(vertices.shape[0]))
        values[0::4] = pixelValues
        values[1::4] = pixelValues
        values[2::4] = pixelValues
        values[3::4] = pixelValues

        plus = numpy.array([0, 1, 2, 2, 3, 0], dtype=numpy.uint32)
        indexes = (numpy.atleast_2d(4 * numpy.arange(vertices.shape[0] // 4, dtype=numpy.uint32)).T + plus).ravel()
        indexes = indexes.astype(numpy.uint32)

        colormap = self.__colormap
        if colormap is None:
            colormap = colors.Colormap(name="inferno", normalization=colors.Colormap.LOGARITHM)

        item = mesh.ColormapMesh()
        item.moveToThread(qt.QApplication.instance().thread())
        item.setData(mode="triangles",
                     position=vertices,
                     value=values,
                     indices=indexes,
                     copy=False)
        item.setColormap(colormap)
        self.__detectorItem = item
        return True
github silx-kit / silx / test / colorbar.py View on Github external
self.colormap1 = Colormap.Colormap(name='green',
                                           normalization='log',
                                           vmin=None,
                                           vmax=None)
        self.plot = PlotWidget(parent=self)
        self.plot.addImage(data=image1,
                           origin=(0, 0),
                           legend='image1',
                           colormap=self.colormap1)
        self.plot.addImage(data=image2,
                           origin=(100, 0),
                           legend='image2',
                           colormap=self.colormap1)

        # red colormap
        self.colormap2 = Colormap.Colormap(name='red',
                                           normalization='linear',
                                           vmin=None,
                                           vmax=None)
        self.plot.addImage(data=image3,
                           origin=(0, 100),
                           legend='image3',
                           colormap=self.colormap2)
        self.plot.addImage(data=image4,
                           origin=(100, 100),
                           legend='image4',
                           colormap=self.colormap2)
        # gray colormap
        self.colormap3 = Colormap.Colormap(name='gray',
                                           normalization='linear',
                                           vmin=1.0,
                                           vmax=20.0)
github silx-kit / silx / silx / gui / plot / PlotWidget.py View on Github external
image.
        It only affects future calls to :meth:`addImage` without the colormap
        parameter.

        :param ~silx.gui.colors.Colormap colormap:
            The description of the default colormap, or
            None to set the colormap to a linear
            autoscale gray colormap.
        """
        if colormap is None:
            colormap = Colormap(name=silx.config.DEFAULT_COLORMAP_NAME,
                                normalization='linear',
                                vmin=None,
                                vmax=None)
        if isinstance(colormap, dict):
            self._defaultColormap = Colormap._fromDict(colormap)
        else:
            assert isinstance(colormap, Colormap)
            self._defaultColormap = colormap
        self.notify('defaultColormapChanged')
github vasole / pymca / PyMca5 / PyMcaGui / pymca / SilxGLWindow.py View on Github external
#     item3d = items.ImageData()
        #     item3d.setData(stackData[i])
        #     item3d.setLabel("frame %d" % i)
        #     origin[2] = i                  # shift each frame by 1
        #     item3d.setTranslation(*origin)
        #     item3d.setScale(*delta)
        #     group.addItem(item3d)
        # self._sceneGlWindow.getSceneWidget().addItem(group)

        item3d = self._sceneGlWindow.getSceneWidget().add3DScalarField(stackData)
        item3d.setLabel(legend)
        item3d.setTranslation(*origin)
        item3d.setScale(*delta)
        item3d.addIsosurface(mean_isolevel, "blue")
        for cp in item3d.getCutPlanes():
            cp.setColormap(Colormap(name="temperature"))
github silx-kit / silx / silx / gui / plot / CompareImages.py View on Github external
# Avoid to change the colormap range when the separator is moving
        # TODO: The colormap histogram will still be wrong
        mode1 = self.__getImageMode(data1)
        mode2 = self.__getImageMode(data2)
        if mode1 == "intensity" and mode1 == mode2:
            if self.__data1.size == 0:
                vmin = self.__data2.min()
                vmax = self.__data2.max()
            elif self.__data2.size == 0:
                vmin = self.__data1.min()
                vmax = self.__data1.max()
            else:
                vmin = min(self.__data1.min(), self.__data2.min())
                vmax = max(self.__data1.max(), self.__data2.max())
            colormap = Colormap(vmin=vmin, vmax=vmax)
            self.__image1.setColormap(colormap)
            self.__image2.setColormap(colormap)
github silx-kit / silx / silx / gui / plot / items / core.py View on Github external
def __init__(self):
        self._colormap = Colormap()
        self._colormap.sigChanged.connect(self._colormapChanged)
        self.__data = None
        self.__cacheColormapRange = {}  # Store {normalization: range}
github silx-kit / silx / silx / gui / widgets / LegendIconWidget.py View on Github external
def _toLut(self, colormap):
        """Returns an internal LUT object used by this widget to manage
        a colormap LUT.

        If the argument is a `Colormap` object, only the current state will be
        displayed. The object itself will not be stored, and further changes
        of this `Colormap` will not update this widget.

        :param Union[str,numpy.ndarray,Colormap] colormap: The colormap to
            display
        :rtype: Union[None,str,numpy.ndarray]
        """
        if isinstance(colormap, colors.Colormap):
            # Helper to allow to support Colormap objects
            c = colormap.getName()
            if c is None:
                c = colormap.getNColors()
            colormap = c

        return colormap
github silx-kit / silx / silx / gui / colors.py View on Github external
def setPreferredColormaps(colormaps):
    """Set the list of preferred colormap names.

    Warning: If a colormap name is not available
    it will be removed from the list.

    :param colormaps: Not empty list of colormap names
    :type colormaps: iterable of str
    :raise ValueError: if the list of available preferred colormaps is empty.
    """
    supportedColormaps = Colormap.getSupportedColormaps()
    colormaps = [cmap for cmap in colormaps if cmap in supportedColormaps]
    if len(colormaps) == 0:
        raise ValueError("Cannot set preferred colormaps to an empty list")

    global _PREFERRED_COLORMAPS
    _PREFERRED_COLORMAPS = colormaps
github silx-kit / silx / silx / gui / widgets / RangeSlider.py View on Github external
"""
        if profile is None:
            self.setSliderPixmap(None)
            return

        profile = numpy.array(profile, copy=False)

        if profile.size == 0:
            self.setSliderPixmap(None)
            return

        if colormap is None:
            colormap = colors.Colormap()
        elif isinstance(colormap, str):
            colormap = colors.Colormap(name=colormap)
        assert isinstance(colormap, colors.Colormap)

        rgbImage = colormap.applyToData(profile.reshape(1, -1))[:, :, :3]
        qimage = convertArrayToQImage(rgbImage)
        qpixmap = qt.QPixmap.fromImage(qimage)
        self.setGroovePixmap(qpixmap)