Python pyqtgraph.LinearRegionItem() Examples

The following are 10 code examples of pyqtgraph.LinearRegionItem(). 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: AttributeCharts.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, iface, plot):
        QObject.__init__(self)

        self.iface = iface
        self.plot = plot
        self.add_selection = False
        self.just_selected = False
        self.show_lines = True

        if has_pyqtgraph:
            self.plot.setClipToView(True)
            self.plot.enableAutoRange(enable=True)
            self.hist_selection = pg.PlotCurveItem()
            self.scatter_selection = []
            self.scatter = pg.ScatterPlotItem()
            self.scatter_points = {}
            self.region = pg.LinearRegionItem()
            #self.selected_points = []
            self.selected_points = pg.ScatterPlotItem()
            self.regress_line = pg.InfiniteLine()
            #self.roi = None

    #----
    # Histogram functions 
Example #2
Source File: AttributeCharts.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 6 votes vote down vote up
def drawHistogram(self, values, xmin, xmax, bins):
        # compute the histogram
        if bins >= 50:
            bin = 51
        else:
            bin = bins+1
        y, x = np.histogram(values, bins=np.linspace(xmin, xmax, num=bin))
        # plot the chart
        if has_pyqtgraph:
            curve = pg.PlotCurveItem()
            self.plot.clear()
            curve.setData(x, y, stepMode=True, fillLevel=0, brush=(230, 230, 230), pen=pg.mkPen(None))
            self.plot.addItem(curve)
            # add the selection tool
            self.region = pg.LinearRegionItem([xmax,xmax],bounds=[xmin, xmax])
            self.region.sigRegionChangeFinished.connect(self.changedHistogramSelection)
            if self.show_lines:
                self.plot.addItem(self.region)
            # add the selection plot
            self.clearHistogramSelection()
            self.hist_selection = pg.PlotCurveItem()
            self.plot.addItem(self.hist_selection)

    # allow selection of items in chart and selecting them on the map 
Example #3
Source File: gccNMFInterface.py    From gcc-nmf with MIT License 6 votes vote down vote up
def initMaskFunctionPlot(self):
        self.gccPHATPlotWidget = self.createGraphicsLayoutWidget(self.backgroundColor, contentMargins=(6, 12, 18, 10))
        self.gccPHATPlotItem = self.gccPHATPlotWidget.addPlot()
        self.gccPHATPlotItem.getViewBox().setBackgroundColor((255, 255, 255, 150))
        self.gccPHATPlot = self.gccPHATPlotItem.plot()
        self.gccPHATPlot.setPen((0, 0, 0))
        self.gccPHATPlotItem.hideAxis('left')
        self.gccPHATPlotItem.hideAxis('bottom')
        self.gccPHATPlotItem.hideButtons()
        self.gccPHATPlotItem.setXRange(0, self.numTDOAs - 1)
        
        self.targetTDOARegion = pg.LinearRegionItem([self.targetTDOAIndex - self.targetTDOAEpsilon, self.targetTDOAIndex + self.targetTDOAEpsilon],
                                                    bounds=[0, self.numTDOAs - 1], movable=True)
        self.targetTDOARegion.sigRegionChangeFinished.connect(self.tdoaRegionChanged)
        
        self.targetWindowFunctionPen = pg.mkPen((0, 0, 204, 255), width=2)  # , style=QtCore.Qt.DashLine)
        self.targetWindowFunctionPlot = TargetWindowFunctionPlot(self.targetTDOARegion, self.targetModeWindowTDOASlider, self.targetModeWindowBetaSlider, self.targetModeWindowNoiseFloorSlider, self.targetModeWindowWidthSlider, self.numTDOAs, pen=self.targetWindowFunctionPen)
        self.gccPHATPlotItem.addItem(self.targetWindowFunctionPlot)
        self.targetWindowFunctionPlot.updateData() 
Example #4
Source File: waveformwidget.py    From dunya-desktop with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, values=[0, 1], orientation=None, brush=None,
                 movable=True, bounds=None):
        pg.LinearRegionItem.__init__(self, values=values, brush=brush,
                                     orientation=orientation, movable=movable,
                                     bounds=bounds) 
Example #5
Source File: waveformwidget.py    From dunya-desktop with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, values, label_section, color):
        pg.LinearRegionItem.__init__(self, values=values, movable=False)

        for line in self.lines:
            line.setPen(pg.mkPen(None))
        self.setBrush(pg.mkBrush(color))
        self.label = label_section

        # signals
        self.item_initialized.emit(self) 
Example #6
Source File: renderers.py    From binglide with MIT License 5 votes vote down vote up
def setup_region(self):
        self.region = pg.LinearRegionItem(orientation=pg.LinearRegionItem.Horizontal)
        self.view.addItem(self.region, ignoreBounds=True)
        self.region.sigRegionChangeFinished.connect(self.region_update)
        self.region.sigRegionChanged.connect(self.region_changed)
        self.needs_region = False 
Example #7
Source File: _hsiDialog.py    From hypers with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, X: 'hp.Dataset', parent=None):
        super(HSIDialog, self).__init__(parent)
        self.setupUi(self)
        self.setWindowTitle('View Hyperspectral Data')

        if not isinstance(X, hp.hparray):
            raise TypeError('Data needs to be passed to skhyper.process.Process first')

        self._X = X

        self.shape = None
        self.dimensions = None

        self.slider.valueChanged.connect(self.update_layer)
        self.updateImage.clicked.connect(self.update_image)
        self.updateSpectrum.clicked.connect(self.update_spectrum)
        self.Reset.clicked.connect(self.reset)

        # --- Setting image/plot settings -----------------------
        self.spec_lo = 0
        self.spec_hi = 0

        self.pgLRI = pg.LinearRegionItem()
        self.specwin.addItem(self.pgLRI)

        self.pgLRI.sigRegionChanged.connect(self.spec_region_updated)

        self.plotline = self.specwin.plot()
        # -------------------------------------------------------

        self.load_data() 
Example #8
Source File: __init__.py    From finplot with MIT License 5 votes vote down vote up
def add_band(y0, y1, color=band_color, ax=None):
    ax = _create_plot(ax=ax, maximize=False)
    lr = pg.LinearRegionItem([y0,y1], orientation=pg.LinearRegionItem.Horizontal, brush=pg.mkBrush(color), movable=False)
    lr.lines[0].setPen(pg.mkPen(None))
    lr.lines[1].setPen(pg.mkPen(None))
    lr.setZValue(-10)
    ax.addItem(lr) 
Example #9
Source File: timeserieswidget.py    From dunya-desktop with GNU General Public License v3.0 4 votes vote down vote up
def add_1d_view(self):
        """
        Adds a 1d view to TimeSeriesWidget where you can plot and add items on it.
        """

        # To customize the plot axises, create new ones.
        x_axis = pg.AxisItem('bottom')  # x-axis
        x_axis.enableAutoSIPrefix(enable=False)  # Prevent automatic SI
        # prefix scaling on this axis.
        x_axis.setGrid(100)  # the alpha value of grids on x-axis

        y_axis = pg.AxisItem('left')  # x-axis
        y_axis.enableAutoSIPrefix(enable=False)  # Prevent automatic SI
        # prefix scaling on this axis.
        axis_items = {'left': y_axis, 'bottom': x_axis}

        # add plot
        self.zoom_selection = self.centralWidget.addPlot(axisItems=axis_items)

        # disable the mouse events and menu events
        self.zoom_selection.setMouseEnabled(x=False, y=False)
        self.zoom_selection.setMenuEnabled(False)

        # initialize a cursor object. Height of cursor is 20000.
        self.vline = pg.ROI(pos=[0, 0], size=[0, 20000], angle=0,
                            pen=CURSOR_PEN)
        self.zoom_selection.addItem(self.vline)  # add item to plot area

        # add y-axis region
        self.right_axis = self.centralWidget.addPlot(row=0, col=1)

        # disable the mouse events and menu events
        self.right_axis.setMouseEnabled(x=False, y=False)
        self.right_axis.setMenuEnabled(False)

        self.right_axis.setMaximumWidth(125)  # maximum width 125
        self.right_axis.setContentsMargins(0, 0, 0, 40)  # set 40 left margin

        self.right_axis.hideAxis(axis="left")  # hide left-axis
        self.right_axis.hideAxis(axis="bottom")  # hide botton-axis
        self.right_axis.setYRange(0, 20000, padding=0)
        # show right axis
        self.right_axis.setLabel(axis="right", text="Frequency (Hz)")

        # initialize a linear region item
        orientation = pg.LinearRegionItem.Horizontal  # set the item horizontal
        self.region_yaxis = pg.LinearRegionItem(values=[0, 20000],
                                                brush=YAXIS_BRUSH,
                                                orientation=orientation,
                                                bounds=[0, 20000])
        self.right_axis.addItem(self.region_yaxis)  # add item to right axis

        # set region changed signal to set y axis range in the plot
        self.region_yaxis.sigRegionChangeFinished.connect(
            self.change_yaxis_range) 
Example #10
Source File: label_events.py    From ConvNetQuake with MIT License 4 votes vote down vote up
def plot_trace(self):
    event_time = self.filtered_catalog.utc_timestamp.values[self.event_idx]
    self.statusBar.showMessage('Event {} of {}: {}'.format(
      self.event_idx+1, self.num_events, utc.UTCDateTime(event_time)))

    window_sz = 20 # in sec
    utc_time = utc.UTCDateTime(event_time)
    start = utc_time
    end = utc_time+window_sz
    local_stream = self.stream.slice(start, end)
    local_stream.filter('highpass', freq=2.0)

    sample_rate = local_stream[0].stats.sampling_rate
    npts = local_stream[0].stats.npts

    event_sample = (utc_time-start)*sample_rate

    n_traces = len(local_stream)
    n_samples = len(local_stream[0].data)
    data = np.zeros((n_traces, n_samples), dtype=np.float32)
    for i in range(n_traces):
        data[i, :] = local_stream[i].data[...]
        mean = np.mean(data[i, :])
        data[i, :] -= mean

    self.trace_x.clear()
    self.trace_y.clear()
    self.trace_z.clear()

    self.trace_x.plot(data[0, :], pen=(255,120,120,200))
    self.trace_y.plot(data[1, :], pen=(120,255,120,200))
    self.trace_z.plot(data[2, :], pen=(120,120,255,200))

    self.lrx = pg.LinearRegionItem([event_sample,event_sample+sample_rate*1])
    self.lrx.setZValue(-10)
    self.trace_x.addItem(self.lrx)

    # lry = pg.LinearRegionItem([400,700])
    # lry.setZValue(-10)
    # self.trace_y.addItem(lry)
    #
    # lrz = pg.LinearRegionItem([400,700])
    # lrz.setZValue(-10)
    # self.trace_z.addItem(lrz)
    #
    # regions = [lrx, lry, lrz]
    #
    # def updateRange(lr, regions):
    #   for l in regions:
    #     if l != lr:
    #       l.setRegion(lr.getRegion())
    #
    # # for l in regions:
    # lrx.sigRegionChanged.connect(lambda : updateRange(lrx, regions))
    # lry.sigRegionChanged.connect(lambda : updateRange(lry, regions))
    # lrz.sigRegionChanged.connect(lambda : updateRange(lrz, regions))