Python pyqtgraph.PlotDataItem() Examples

The following are 20 code examples of pyqtgraph.PlotDataItem(). 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: charts.py    From Quantdom with Apache License 2.0 7 votes vote down vote up
def _update_ind_charts(self):
        for ind, d in self.indicators:
            curve = pg.PlotDataItem(d, pen='b', antialias=True)
            ind.addItem(curve)
            ind.hideAxis('left')
            ind.showAxis('right')
            # ind.setAspectLocked(1)
            ind.setXLink(self.chart)
            ind.setLimits(
                xMin=Quotes[0].id,
                xMax=Quotes[-1].id,
                minXRange=60,
                yMin=Quotes.open.min() * 0.98,
                yMax=Quotes.open.max() * 1.02,
            )
            ind.showGrid(x=True, y=True)
            ind.setCursor(QtCore.Qt.BlankCursor) 
Example #2
Source File: tab_aps.py    From kite with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent_plot):
        KiteSubplot.__init__(self, parent_plot)

        self.aps_correlation = pg.ScatterPlotItem(
            antialias=True,
            brush=brush_aps,
            pen=pen_aps,
            size=4)

        self.aps_model = pg.PlotDataItem(
            antialias=True,
            pen=pen_aps_model)

        self.legend = pg.LegendItem(offset=(0., .5))

        self.legend.setParentItem(self.plot.graphicsItem())
        self.legend.addItem(self.aps_model, '')

        self.addItem(self.aps_correlation)
        self.addItem(self.aps_model)

        self.plot.setLabels(
            bottom='Elevation (m)',
            left='Displacement (m)') 
Example #3
Source File: tab_covariance.py    From kite with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent_plot):
        KiteSubplot.__init__(self, parent_plot)

        self.power = pg.PlotDataItem(antialias=True)
        # self.power_lin = pg.PlotDataItem(antialias=True, pen=pen_green_dash)

        self.power.setZValue(10)
        self.plot.setLabels(
            bottom='Wavenumber (cycles/m)',
            left='Power (m<sup>2</sup>)')

        self.plot.setLogMode(x=True, y=True)

        # self.legend = pg.LegendItem(offset=(0., .5))
        # self.legend.setParentItem(self.plot.graphicsItem())
        # self.legend.addItem(self.power_lin, 'Log-linear model')

        self.addItem(self.power)
        # self.addItem(self.power_lin) 
Example #4
Source File: test_PlotDataItem.py    From tf-pose with Apache License 2.0 6 votes vote down vote up
def test_fft():
    f = 20.
    x = np.linspace(0, 1, 1000)
    y = np.sin(2 * np.pi * f * x)
    pd = pg.PlotDataItem(x, y)
    pd.setFftMode(True)    
    x, y = pd.getData()
    assert abs(x[np.argmax(y)] - f) < 0.03
    
    x = np.linspace(0, 1, 1001)
    y = np.sin(2 * np.pi * f * x)
    pd.setData(x, y)
    x, y = pd.getData()
    assert abs(x[np.argmax(y)]- f) < 0.03
    
    pd.setLogMode(True, False)
    x, y = pd.getData()
    assert abs(x[np.argmax(y)] - np.log10(f)) < 0.01 
Example #5
Source File: tab_covariance.py    From kite with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent_plot):
        KiteSubplot.__init__(self, parent_plot)

        self.structure = pg.PlotDataItem(
            antialias=True,
            pen=pen_covariance_active)
        self.variance = self.VarianceLine(
            pen=pen_variance,
            angle=0, movable=True, hoverPen=pen_variance_highlight,
            label='Variance: {value:.5f}',
            labelOpts={'position': .975,
                       'anchors': ((1., 0.), (1., 1.)),
                       'color': pg.mkColor(255, 255, 255, 155)})
        self.plot.setLabels(
            bottom=('Distance', 'm'),
            left='Variance (m<sup>2</sup>)')

        self.addItem(self.structure)
        self.addItem(self.variance)
        self.variance.sigPositionChangeFinished.connect(
            self.changeVariance) 
Example #6
Source File: plot_item_buffer.py    From mushroom-rl with MIT License 6 votes vote down vote up
def erase(self, item):
        """
        Erase curve in case it is drawn.

        Args:
             item (PlotDataItem): curve item associated with a data buffer to be
                erased.

        """
        index_item = self.plot_data_items_list.index(item)

        try:
            self.legend.removeItem(self._curves_names[index_item])
        except:
            pass

        if item in self.listDataItems():
            self.removeItem(item) 
Example #7
Source File: analysis.py    From pyFlightAnalysis with MIT License 6 votes vote down vote up
def draw_predefined_graph(self, name):
        
        def add_context_action(ax):
            def callback(*args, **kargs):
                for item in ax.items():
                    if isinstance(item, pg.PlotDataItem):
                        if item.opts['symbol'] is None:
                            item.setData(item.xData, item.yData, symbol='s')
                        else:
                            item.setData(item.xData, item.yData, symbol=None) 
            return callback
        
        if name == 'XY_Estimation':
            graph_xy =  pg.GraphicsLayoutWidget()
            self.default_tab.addTab(graph_xy, name)
            ax = graph_xy.addPlot(row=0, col=0)
            show_marker_action = QtGui.QAction('show/hide marker', graph_xy)
            show_marker_action.triggered.connect(add_context_action(ax))
            data_index = list(list(self.data_dict.keys())).index('vehicle_local_position')
            x = self.log_data_list[data_index].data['x']
            y = self.log_data_list[data_index].data['y']
            # plot the xy trace line in red
            ax.plot(x, y, pen=(255, 0, 0)) 
Example #8
Source File: qt_plot_area.py    From enamlx with MIT License 6 votes vote down vote up
def _redraw_plot(self):
        self._pending_refreshes-=1
        if self._pending_refreshes!=0:
            return # Another change occurred
        
        if self.plot:
            self.plot.clear()
        if self.viewbox:
            self.viewbox.close()
        
        d = self.declaration
        
        data = self._format_data()
        style = self._format_style()

        if not self.is_root and d.parent.multi_axis:
            self._refresh_multi_axis()
            self.plot = self.viewbox.addItem(pg.PlotDataItem(*data,**style))
        else:  
            self.plot = self.widget.plot(*data,**style) 
Example #9
Source File: plots.py    From autopilot with Mozilla Public License 2.0 6 votes vote down vote up
def update(self, data):
        """
        data is doubled and then every other value is set to 0.5,
        then :meth:`~pyqtgraph.PlotDataItem.curve.setData` is used with
        `connect='pairs'` to make line segments.

        Args:
            data (:class:`numpy.ndarray`): an x_width x 2 array where
                column 0 is trial number and column 1 is the value,
                where value can be "L", "C", "R" or a float.
        """
        # data should come in as an n x 2 array,
        # 0th column - trial number (x), 1st - (y) value
        data[data=="R"] = 1
        data[data=="L"] = 0
        data[data=="C"] = 0.5
        data = data.astype(np.float)

        xs = np.repeat(data[...,0],2)
        ys = np.repeat(data[...,1],2)
        ys[::2] = 0.5

        self.curve.setData(xs, ys, connect='pairs', pen='k') 
Example #10
Source File: gccNMFInterface.py    From gcc-nmf with MIT License 5 votes vote down vote up
def initVisualizationWidgets(self):
        self.inputSpectrogramWidget = self.createGraphicsLayoutWidget(self.backgroundColor)
        inputSpectrogramViewBox = self.inputSpectrogramWidget.addViewBox()
        self.inputSpectrogramHistoryImageItem = pg.ImageItem(self.inputSpectrogramHistory.values)  # , border=self.borderColor)
        inputSpectrogramViewBox.addItem(self.inputSpectrogramHistoryImageItem)
        inputSpectrogramViewBox.setRange(xRange=(0, self.inputSpectrogramHistory.values.shape[1]), yRange=(0, self.inputSpectrogramHistory.values.shape[0]), padding=0)
        
        self.outputSpectrogramWidget = self.createGraphicsLayoutWidget(self.backgroundColor)
        outputSpectrogramViewBox = self.outputSpectrogramWidget.addViewBox()
        self.outputSpectrogramHistoryImageItem = pg.ImageItem(self.outputSpectrogramHistory.values)  # , border=self.borderColor)
        outputSpectrogramViewBox.addItem(self.outputSpectrogramHistoryImageItem)
        outputSpectrogramViewBox.setRange(xRange=(0, self.outputSpectrogramHistory.values.shape[1] - 1), yRange=(0, self.outputSpectrogramHistory.values.shape[0] - 1), padding=0)
        
        self.gccPHATHistoryWidget = self.createGraphicsLayoutWidget(self.backgroundColor)
        gccPHATHistoryViewBox = self.gccPHATHistoryWidget.addViewBox()  # invertY=True)
        self.gccPHATImageItem = pg.ImageItem(self.gccPHATHistory.values)  # , border=self.borderColor)
        gccPHATHistoryViewBox.addItem(self.gccPHATImageItem)
        gccPHATHistoryViewBox.setRange(xRange=(0, self.gccPHATHistory.values.shape[1] - 1), yRange=(0, self.gccPHATHistory.values.shape[0] - 1), padding=0)
        
        self.tdoaPlotDataItem = pg.PlotDataItem( pen=pg.mkPen((255, 0, 0, 255), width=4) )
        gccPHATHistoryViewBox.addItem(self.tdoaPlotDataItem)

        dictionarySize = self.dictionarySizes[self.dictionarySizeDropDown.currentIndex()]
        self.coefficientMaskWidget = self.createGraphicsLayoutWidget(self.backgroundColor)
        self.coefficientMaskViewBox = self.coefficientMaskWidget.addViewBox()
        self.coefficientMaskHistory = self.coefficientMaskHistories[dictionarySize]
        self.coefficientMaskHistoryImageItem = pg.ImageItem()  # , border=self.borderColor)
        self.coefficientMaskViewBox.addItem(self.coefficientMaskHistoryImageItem)
        
        self.dictionaryWidget = self.createGraphicsLayoutWidget(self.backgroundColor)
        self.dictionaryViewBox = self.dictionaryWidget.addViewBox()
        self.dictionaryImageItem = pg.ImageItem()  # 1 - visualizedDictionary)#, border=self.borderColor)
        self.dictionaryViewBox.addItem(self.dictionaryImageItem)
        self.dictionarySizeChanged(False) 
Example #11
Source File: plot.py    From asammdf with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_color(self, uuid, color):
        _, index = self.signal_by_uuid(uuid)
        self.signals[index].color = color
        self.curves[index].setPen(color)
        if self.curvetype == pg.PlotDataItem:
            self.curves[index].setSymbolPen(color)
            self.curves[index].setSymbolBrush(color)

        if uuid == self.current_uuid:
            self.y_axis.setPen(color)
            self.y_axis.setTextPen(color) 
Example #12
Source File: plot_item_buffer.py    From mushroom-rl with MIT License 5 votes vote down vote up
def draw(self, item):
        """
        Draw curve.

        Args:
            item (PlotDataItem): curve item associated with a DataBuffer to be
                drawn.

        """
        if item not in self.listDataItems():
            self.addItem(item) 
Example #13
Source File: __init__.py    From finplot with MIT License 5 votes vote down vote up
def _get_color(ax, style, wanted_color):
    if type(wanted_color) == str:
        return wanted_color
    index = wanted_color if type(wanted_color) == int else None
    if style is None or style=='-':
        if index is None:
            index = len([i for i in ax.items if isinstance(i,pg.PlotDataItem) and not i.opts['symbol'] and not i.opts['handed_color']])
        return soft_colors[index%len(soft_colors)]
    if index is None:
        index = len([i for i in ax.items if isinstance(i,pg.PlotDataItem) and i.opts['symbol'] and not i.opts['handed_color']])
    return hard_colors[index%len(hard_colors)] 
Example #14
Source File: charts.py    From Quantdom with Apache License 2.0 5 votes vote down vote up
def _get_chart_points(style):
    if style == ChartType.CANDLESTICK:
        return CandlestickItem()
    elif style == ChartType.BAR:
        return BarItem()
    return pg.PlotDataItem(Quotes.close, pen='b') 
Example #15
Source File: lineplot1d.py    From argos with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, collector, parent=None):
        """ Constructor. See AbstractInspector constructor for parameters.
        """
        super(PgLinePlot1d, self).__init__(collector, parent=parent)

        # The sliced array is kept in memory. This may be different per inspector, e.g. 3D
        # inspectors may decide that this uses to much memory. The slice is therefor not stored
        # in the collector.
        self.slicedArray = None

        self.graphicsLayoutWidget = pg.GraphicsLayoutWidget()
        self.contentsLayout.addWidget(self.graphicsLayoutWidget)
        self.titleLabel = self.graphicsLayoutWidget.addLabel('<plot title goes here>', 0, 0)

        self.plotItem = ArgosPgPlotItem()
        self.viewBox = self.plotItem.getViewBox()
        self.graphicsLayoutWidget.addItem(self.plotItem, 1, 0)

        # Probe
        probePen = pg.mkPen("#BFBFBF")
        probeShadowPen = pg.mkPen("#00000064", width=3)
        self.crossLineVerShadow = pg.InfiniteLine(angle=90, movable=False, pen=probeShadowPen)
        self.crossLineVertical = pg.InfiniteLine(angle=90, movable=False, pen=probePen)
        self.probeDataItem = pg.PlotDataItem(symbolPen=probePen)
        self.probeLabel = self.graphicsLayoutWidget.addLabel('', 2, 0, justify='left')

        # Configuration tree
        self._config = PgLinePlot1dCti(pgLinePlot1d=self, nodeName='1D line plot')

        # Connect signals
        # Based mouseMoved on crosshair.py from the PyQtGraph examples directory.
        # I did not use the SignalProxy because I did not see any difference.
        self.plotItem.scene().sigMouseMoved.connect(self.mouseMoved) 
Example #16
Source File: pgctis.py    From argos with GNU General Public License v3.0 5 votes vote down vote up
def createPlotDataItem(self):
        """ Creates a PyQtGraph PlotDataItem from the config values
        """
        antialias = self.antiAliasCti.configValue

        color = self.penColor
        if self.lineCti.configValue:
            pen = QtGui.QPen()
            pen.setCosmetic(True)
            pen.setColor(color)
            pen.setWidthF(self.lineWidthCti.configValue)
            pen.setStyle(self.lineStyleCti.configValue)
            shadowCti = self.lineCti.findByNodePath('shadow')
            shadowPen = shadowCti.createPen(altStyle=pen.style(), altWidth=2.0 * pen.widthF())
        else:
            pen = None
            shadowPen = None

        drawSymbols = self.symbolCti.configValue
        symbolShape = self.symbolShapeCti.configValue if drawSymbols else None
        symbolSize  = self.symbolSizeCti.configValue if drawSymbols else 0.0
        symbolPen = None # otherwise the symbols will also have dotted/solid line.
        symbolBrush = QtGui.QBrush(color) if drawSymbols else None

        plotDataItem = pg.PlotDataItem(antialias=antialias, pen=pen, shadowPen=shadowPen,
                                       symbol=symbolShape, symbolSize=symbolSize,
                                       symbolPen=symbolPen, symbolBrush=symbolBrush)
        return plotDataItem 
Example #17
Source File: analysis.py    From pyFlightAnalysis with MIT License 5 votes vote down vote up
def update_ROI_graph(self):
        items_to_be_removed = []
        for item in self.detail_graph.items:
            if isinstance(item, pg.PlotDataItem):
                items_to_be_removed.append(item)
                
        for item in items_to_be_removed:
            self.detail_graph.removeItem(item)
            
        items = self.main_graph_t.items
        for item in items:
            if isinstance(item, pg.PlotDataItem):
                self.detail_graph.plot(item.xData, item.yData, symbol=item.opts['symbol'], pen=item.opts['pen']) 
Example #18
Source File: tab_covariance.py    From kite with GNU General Public License v3.0 5 votes vote down vote up
def setGradientEditor(self, gradient_editor):
            ge = gradient_editor
            image = self.image

            hist_pen = pg.mkPen((170, 57, 57, 255), width=1.)
            image.setLookupTable(ge.getLookupTable)

            def updateLevels():
                image.setLevels(ge.region.getRegion())

            ge.sigLevelChangeFinished.connect(updateLevels)
            ge.sigLevelsChanged.connect(updateLevels)
            updateLevels()

            def updateHistogram():
                h = image.getHistogram()
                if h[0] is None:
                    return
                ge.hist_syn.setData(*h)

            ge.hist_syn = pg.PlotDataItem(pen=hist_pen)
            ge.hist_syn.rotate(90.)
            ge.vb.addItem(ge.hist_syn)
            updateHistogram()

            image.sigImageChanged.connect(updateHistogram) 
Example #19
Source File: tab_covariance.py    From kite with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent_plot):
        KiteSubplot.__init__(self, parent_plot)
        self.plot.setLabels(
            bottom=('Distance', 'm'),
            left='Covariance (m<sup>2</sup>)')

        self.cov_spectral = pg.PlotDataItem(antialias=True)
        self.cov_spectral.setZValue(10)

        self.cov_spatial = pg.PlotDataItem(antialias=True)

        self.cov_model = pg.PlotDataItem(
            antialias=True,
            pen=pen_covariance_model)

        self.variance = self.VarianceLine(
            pen=pen_variance,
            angle=0, movable=True, hoverPen=pen_variance_highlight,
            label='Variance: {value:.5f}',
            labelOpts={'position': .975,
                       'anchors': ((1., 0.), (1., 1.)),
                       'color': pg.mkColor(255, 255, 255, 155)})
        self.variance.setToolTip('Move to change variance')
        self.variance.sigPositionChangeFinished.connect(self.setVariance)

        self.addItem(self.cov_spectral)
        self.addItem(self.cov_spatial)
        self.addItem(self.cov_model)
        self.addItem(self.variance)
        # self.cov_lin_pow = pg.PlotDataItem(antialias=True,
        #                                    pen=pen_green_dash)
        # self.addItem(self.cov_lin_pow)

        self.legend = pg.LegendItem(offset=(0., .5))

        self.legend.setParentItem(self.plot.graphicsItem())
        self.legend.addItem(self.cov_model, '') 
Example #20
Source File: analysis.py    From pyFlightAnalysis with MIT License 4 votes vote down vote up
def update_graph(self):
        # update tableView
        # clear 
        self.plotting_data_tableView.setRowCount(0)
        # add
        for ind, (item_id, item) in enumerate(self.data_plotting.items()):
            self.plotting_data_tableView.insertRow(ind)
            self.plotting_data_tableView.setCellWidget(ind, 0, QtGui.QLabel(item[0]))
            chkbox = Checkbox(item_id, '')
            chkbox.setChecked(item[1])
            chkbox.sigStateChanged.connect(self.callback_visible_changed)
            self.plotting_data_tableView.setCellWidget(ind, 1, chkbox)
            curve = item[2]
            color = curve.opts['pen']
            if isinstance(color, QtGui.QColor):
                color = color.red(), color.green(), color.blue()
            marker = curve.opts['symbol']
            marker_dict = OrderedDict([(None,'None'), ('s','☐'), ('t','▽'), ('o','○'), ('+','+')])
            color_text = '#{0[0]:02x}{0[1]:02x}{0[2]:02x}'.format(color)
            lbl_txt = "<font color='{0}'>{1}</font> {2}".format(color_text,'▇▇',str(marker_dict[marker]))
            lbl = PropertyLabel(item_id, self, lbl_txt)
            lbl.sigPropertyChanged.connect(self.callback_property_changed)
            self.plotting_data_tableView.setCellWidget(ind, 2, lbl)
        
        # update curve
        # remove curves in graph
        items_to_be_removed = []
        for item in self.main_graph_t.items:
            if isinstance(item, pg.PlotDataItem):
                items_to_be_removed.append(item)
        for item in items_to_be_removed:
            self.main_graph_t.removeItem(item)

        self.main_graph_t.legend.scene().removeItem(self.main_graph_t.legend)
        self.main_graph_t.addLegend()
        # redraw curves
        for ind, (item_id, item) in enumerate(self.data_plotting.items()):
            label, showed, curve = item
            color = curve.opts['pen']
            if isinstance(color, QtGui.QColor):
                color = color.red(), color.green(), color.blue()
            data = curve.xData, curve.yData
            marker = curve.opts['symbol']
            symbolSize = curve.opts['symbolSize']
            if showed:
                curve = self.main_graph_t.plot(data[0], data[1], symbol=marker, pen=color, name=label, symbolSize=symbolSize)
                self.data_plotting[item_id][2] = curve 
        self.update_ROI_graph()