Python pyqtgraph.ColorMap() Examples

The following are 6 code examples of pyqtgraph.ColorMap(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyqtgraph , or try the search function .
Example #1
Source File: tab_covariance.py    From kite with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, model, parent):
            from pyqtgraph.graphicsItems.GradientEditorItem import Gradients
            self._component = 'weight'
            self.parent = parent

            KitePlot.__init__(self, model)
            self.model = model

            gradient = Gradients['thermal']

            self.cmap = pg.ColorMap(
                pos=[c[0] for c in gradient['ticks']],
                color=[c[1] for c in gradient['ticks']],
                mode=gradient['mode'])
            self.image.setLookupTable(self.cmap.getLookupTable())

            self.setLabels(
                bottom={'Leaf #', ''},
                left={'Leaf #', ''})

            self.setAspectLocked(True)
            self.setMouseEnabled(x=False, y=False)

            self.hint = {
                'leaf1': 0,
                'leaf2': 0,
                'weight': num.nan}

            self.hint_text.template =\
                '<span style="font-family: monospace; color: #fff;'\
                'background-color: #000;">'\
                'Leaf #1: {leaf1:d} | Leaf #2: {leaf2:d} | '\
                '{weight:e}</span>'

            self.update() 
Example #2
Source File: fishplots.py    From stytra with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, acc, n_points=300):
        super().__init__()
        self.title = "Tail curvature"
        self.acc = acc
        self.headers = None
        self.n_points = n_points

        self.setLayout(QVBoxLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)

        self.display_widget = pg.GraphicsLayoutWidget()
        self.vb_display = pg.ViewBox()
        self.display_widget.addItem(self.vb_display)
        self.image_item = pg.ImageItem()
        self.vb_display.addItem(self.image_item)

        self.image_item.setLevels((-0.6, 0.6))
        self.image_item.setLookupTable(
            pg.ColorMap(
                np.linspace(0, 1, 5),
                np.array(
                    [
                        [0.42107294, 0.80737975, 0.49219722],
                        [0.23166242, 0.39962101, 0.32100403],
                        [0.0, 0.0, 0.0],
                        [0.46170494, 0.30327584, 0.38740225],
                        [0.91677407, 0.58427975, 0.92293321],
                    ]
                ),
            ).getLookupTable(alpha=False)
        )
        self.layout().addWidget(self.display_widget) 
Example #3
Source File: SpectrogramWidget.py    From OpenNFB with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, blockSize = 1024, samplingFreq = 250):
        super(SpectrogramWidget, self).__init__()

        self.blockSize = blockSize

        self.img = pg.ImageItem()
        self.addItem(self.img)

        self.img_array = np.zeros((100, (blockSize/2)+1))

        # bipolar colormap
        pos = np.array([0., 1., 0.5, 0.25, 0.75])
        color = np.array([[0,255,255,255], [255,255,0,255], [0,0,0,255], (0, 0, 255, 255), (255, 0, 0, 255)], dtype=np.ubyte)
        cmap = pg.ColorMap(pos, color)
        lut = cmap.getLookupTable(0.0, 1.0, 256)

        self.img.setLookupTable(lut)
        self.img.setLevels([-50,40])

        freq = np.arange((blockSize/2)+1)/(float(blockSize)/samplingFreq)
        yscale = 1.0/(self.img_array.shape[1]/freq[-1])
        self.img.scale((1./samplingFreq)*blockSize, yscale)

        self.setLabel('left', 'Frequency', units='Hz')

        self.win = np.hanning(blockSize)
        self.show()

        self.buffer = np.zeros(blockSize) 
Example #4
Source File: display.py    From OpenNFB with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, name, **config):
        self.img = pg.ImageItem()
        self.plot_widget = pg.PlotWidget(title=name)
        self.plot_widget.block = self

        self.plot_widget.addItem(self.img)

        #self.img_array = np.zeros((1000, self.CHUNKSZ/2+1))
        self.img_array = np.zeros((1000, 48))

        # bipolar colormap
        pos = np.array([0., 1., 0.5, 0.25, 0.75])
        color = np.array([[0,255,255,255], [255,255,0,255], [0,0,0,255], (0, 0, 255, 255), (255, 0, 0, 255)], dtype=np.ubyte)
        cmap = pg.ColorMap(pos, color)
        lut = cmap.getLookupTable(0.0, 1.0, 256)

        self.img.setLookupTable(lut)
        self.img.setLevels([-2,7])

        FS = 48 * 2

        freq = np.arange((self.CHUNKSZ/2)+1)/(float(self.CHUNKSZ)/FS)
        yscale = 1.0/(self.img_array.shape[1]/freq[-1])
        self.img.scale((1./FS)*self.CHUNKSZ, yscale)

        self.plot_widget.setLabel('left', 'Frequency', units='Hz')

        self.win = np.hanning(self.CHUNKSZ)
        #self.show()
        super(Spectrograph, self).__init__(**config) 
Example #5
Source File: plotting.py    From pygsp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _qtg_plot_signal(G, signal, edges, vertex_size, limits, title):

    qtg, gl, QtGui = _import_qtg()

    if G.coords.shape[1] == 2:
        window = qtg.GraphicsWindow(title)
        view = window.addViewBox()

    elif G.coords.shape[1] == 3:
        if not QtGui.QApplication.instance():
            QtGui.QApplication([])  # We want only one application.
        widget = gl.GLViewWidget()
        widget.opts['distance'] = 10
        widget.show()
        widget.setWindowTitle(title)

    if edges:

        if G.coords.shape[1] == 2:
            adj = _get_coords(G, edge_list=True)
            pen = tuple(np.array(G.plotting['edge_color']) * 255)
            g = qtg.GraphItem(pos=G.coords, adj=adj, symbolBrush=None,
                              symbolPen=None, pen=pen)
            view.addItem(g)

        elif G.coords.shape[1] == 3:
            x, y, z = _get_coords(G)
            pos = np.stack((x, y, z), axis=1)
            g = gl.GLLinePlotItem(pos=pos, mode='lines',
                                  color=G.plotting['edge_color'])
            widget.addItem(g)

    pos = [1, 8, 24, 40, 56, 64]
    color = np.array([[0, 0, 143, 255], [0, 0, 255, 255], [0, 255, 255, 255],
                      [255, 255, 0, 255], [255, 0, 0, 255], [128, 0, 0, 255]])
    cmap = qtg.ColorMap(pos, color)

    signal = 1 + 63 * (signal - limits[0]) / limits[1] - limits[0]

    if G.coords.shape[1] == 2:
        gp = qtg.ScatterPlotItem(G.coords[:, 0],
                                 G.coords[:, 1],
                                 size=vertex_size/10,
                                 brush=cmap.map(signal, 'qcolor'))
        view.addItem(gp)

    if G.coords.shape[1] == 3:
        gp = gl.GLScatterPlotItem(pos=G.coords,
                                  size=vertex_size/3,
                                  color=cmap.map(signal, 'float'))
        widget.addItem(gp)

    if G.coords.shape[1] == 2:
        global _qtg_windows
        _qtg_windows.append(window)
    elif G.coords.shape[1] == 3:
        global _qtg_widgets
        _qtg_widgets.append(widget) 
Example #6
Source File: plotting.py    From pygsp with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def _plot_spectrogram(G, node_idx):
    r"""Plot the graph's spectrogram.

    Parameters
    ----------
    node_idx : ndarray
        Order to sort the nodes in the spectrogram.
        By default, does not reorder the nodes.

    Notes
    -----
    This function is only implemented for the pyqtgraph backend at the moment.

    Examples
    --------
    >>> G = graphs.Ring(15)
    >>> G.plot_spectrogram()

    """
    from pygsp import features

    qtg, _, _ = _import_qtg()

    if not hasattr(G, 'spectr'):
        features.compute_spectrogram(G)

    M = G.spectr.shape[1]
    spectr = G.spectr[node_idx, :] if node_idx is not None else G.spectr
    spectr = np.ravel(spectr)
    min_spec, max_spec = spectr.min(), spectr.max()

    pos = np.array([0., 0.25, 0.5, 0.75, 1.])
    color = [[20, 133, 212, 255], [53, 42, 135, 255], [48, 174, 170, 255],
             [210, 184, 87, 255], [249, 251, 14, 255]]
    color = np.array(color, dtype=np.ubyte)
    cmap = qtg.ColorMap(pos, color)

    spectr = (spectr.astype(float) - min_spec) / (max_spec - min_spec)

    w = qtg.GraphicsWindow()
    w.setWindowTitle("Spectrogram of {}".format(G.__repr__(limit=4)))
    label = 'frequencies {}:{:.2f}:{:.2f}'.format(0, G.lmax/M, G.lmax)
    v = w.addPlot(labels={'bottom': 'nodes',
                          'left': label})
    v.setAspectLocked()

    spi = qtg.ScatterPlotItem(np.repeat(np.arange(G.N), M),
                              np.ravel(np.tile(np.arange(M), (1, G.N))),
                              pxMode=False,
                              symbol='s',
                              size=1,
                              brush=cmap.map(spectr, 'qcolor'))
    v.addItem(spi)

    global _qtg_windows
    _qtg_windows.append(w)