Python pyqtgraph.ViewBox() Examples

The following are 30 code examples of pyqtgraph.ViewBox(). 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: candle_demo.py    From Python-CTPAPI with MIT License 6 votes vote down vote up
def _init_line(self) -> None:
        """
        Create line objects.
        """
        self._v_lines: Dict[str, pg.InfiniteLine] = {}
        self._h_lines: Dict[str, pg.InfiniteLine] = {}
        self._views: Dict[str, pg.ViewBox] = {}

        pen = pg.mkPen(WHITE_COLOR)

        for plot_name, plot in self._plots.items():
            v_line = pg.InfiniteLine(angle=90, movable=False, pen=pen)
            h_line = pg.InfiniteLine(angle=0, movable=False, pen=pen)
            view = plot.getViewBox()

            for line in [v_line, h_line]:
                line.setZValue(0)
                line.hide()
                view.addItem(line)

            self._v_lines[plot_name] = v_line
            self._h_lines[plot_name] = h_line
            self._views[plot_name] = view 
Example #2
Source File: OrthoImageItem.py    From rapidtide with Apache License 2.0 6 votes vote down vote up
def newColorbar(view, left, top, impixpervoxx, impixpervoxy, imgsize):
    cb_xdim = imgsize // 10
    cb_ydim = imgsize
    theviewbox = pg.ViewBox(enableMouse=False)
    theviewbox.setRange(QtCore.QRectF(0, 0, cb_xdim, cb_ydim),
                        xRange=(0, cb_xdim - 1), yRange=(0, cb_ydim - 1), padding=0.0,
                        disableAutoRange=True)
    theviewbox.setAspectLocked()

    thecolorbarwin = pg.ImageItem()
    theviewbox.addItem(thecolorbarwin)
    thecolorbarwin.translate(left, top)
    thecolorbarwin.scale(impixpervoxx, impixpervoxy)

    colorbarvals = np.zeros((cb_xdim, cb_ydim), dtype=np.float64)
    for i in range(0, cb_ydim):
        colorbarvals[:, i] = i * (1.0 / (cb_ydim - 1.0))
    thecolorbarwin.setImage(colorbarvals, levels=[0.0, 1.0])
    return thecolorbarwin, theviewbox 
Example #3
Source File: graphics.py    From suite2p with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent=None, border=None, lockAspect=False, enableMouse=True,
                 invertY=False, enableMenu=True, name=None, invertX=False):
        #pg.ViewBox.__init__(self, border, lockAspect, enableMouse,
                            #invertY, enableMenu, name, invertX)
        super(ViewBox, self).__init__()
        self.border = fn.mkPen(border)
        if enableMenu:
            self.menu = ViewBoxMenu(self)
        self.name = name
        self.parent=parent
        if self.name=="plot2":
            self.setXLink(parent.p1)
            self.setYLink(parent.p1)

        # set state
        self.state['enableMenu'] = enableMenu
        self.state['yInverted'] = invertY 
Example #4
Source File: graphtab.py    From equant with GNU General Public License v2.0 6 votes vote down vote up
def makePI(self, name):
        """生成PlotItem对象"""
        vb = CustomViewBox(self)
        plotItem = pg.PlotItem(viewBox=vb, name=name, axisItems={'bottom': self.axisTime})
        plotItem.setMenuEnabled(False)
        # 仅绘制ViewBox可见范围内的点
        plotItem.setClipToView(True)
        plotItem.showAxis('left')
        # 设置采样模式
        plotItem.setDownsampling(mode='peak')
        plotItem.setRange(xRange=(0, 1), yRange=(0, 1))
        plotItem.getAxis('left').setWidth(70)
        plotItem.getAxis('left').setStyle(tickFont=QtGui.QFont('Roman times', 10, QtGui.QFont.Bold))
        plotItem.getAxis('left').setPen(color=(255, 255, 255, 255), width=0.8)
        plotItem.showGrid(True, True)
        plotItem.hideButtons()

        return plotItem 
Example #5
Source File: fundtab.py    From equant with GNU General Public License v2.0 6 votes vote down vote up
def makePI(self, name):
        """生成PlotItem对象"""
        vb = CustomViewBox(self)
        plotItem = pg.PlotItem(viewBox=vb, name=name, axisItems={'bottom': self.axisTime})
        plotItem.setMenuEnabled(False)
        # 仅绘制ViewBox可见范围内的点
        plotItem.setClipToView(True)
        plotItem.hideAxis('left')
        plotItem.showAxis('right')
        # 设置采样模式
        plotItem.setDownsampling(mode='peak')
        plotItem.setRange(xRange=(0, 1), yRange=(0, 1))
        plotItem.getAxis('right').setWidth(70)
        plotItem.getAxis('right').setStyle(tickFont=QtGui.QFont('Roman times', 10, QtGui.QFont.Bold))
        plotItem.getAxis('right').setPen(color=(255, 255, 255, 255), width=0.8)
        plotItem.showGrid(True, True)
        plotItem.hideButtons()

        return plotItem 
Example #6
Source File: fundtab.py    From equant with GNU General Public License v2.0 6 votes vote down vote up
def mouseDragEvent(self, ev, axis=None):
        # if ev.start==True and ev.finish==False: ##判断拖拽事件是否结束
        pos = ev.pos()
        lastPos = ev.lastPos()
        dif = pos - lastPos

        rect = self.sceneBoundingRect()

        pianyi = dif.x() * self.parent.count * 2 / rect.width()

        self.parent.index -= int(pianyi)
        self.parent.index = max(self.parent.index, 60)
        xMax = self.parent.index + self.parent.count
        xMin = self.parent.index - self.parent.count
        # if xMin < 0:
        #     xMin = 0

        pg.ViewBox.mouseDragEvent(self, ev, axis) 
Example #7
Source File: tools.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def mouseDragEvent(self, ev):
        pg.ViewBox.mouseDragEvent(self, ev) 
Example #8
Source File: tools.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        self.RectMode = 3
        self.setMouseMode(self.RectMode) 
Example #9
Source File: tools.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def wheelEvent(self,ev, axis=None):
        pg.ViewBox.wheelEvent(self, ev, axis) 
Example #10
Source File: graph1.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        self.RectMode = 3
        self.setMouseMode(self.RectMode) 
Example #11
Source File: graph1.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def mouseDragEvent(self, ev):
        pg.ViewBox.mouseDragEvent(self, ev) 
Example #12
Source File: testGraphAnalysis.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        self.RectMode = 3
        self.setMouseMode(self.RectMode) 
Example #13
Source File: testGraphAnalysis.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def mouseDragEvent(self, ev):
        pg.ViewBox.mouseDragEvent(self, ev) 
Example #14
Source File: fundtab.py    From equant with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, parent, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        self.parent = parent
        # 拖动放大模式
        # self.setMouseMode(self.RectMode) 
Example #15
Source File: fundtab.py    From equant with GNU General Public License v2.0 5 votes vote down vote up
def mousePressEvent(self, event):
        pg.ViewBox.mousePressEvent(self, event) 
Example #16
Source File: graphtab.py    From equant with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, parent, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        self.parent = parent
        # 拖动放大模式
        # self.setMouseMode(self.RectMode) 
Example #17
Source File: graphtab.py    From equant with GNU General Public License v2.0 5 votes vote down vote up
def mouseDragEvent(self, ev, axis=None):
        # if ev.start==True and ev.finish==False: ##判断拖拽事件是否结束
        pos = ev.pos()
        lastPos = ev.lastPos()
        dif = pos - lastPos

        rect = self.sceneBoundingRect()

        pianyi = dif.x() * self.parent.count * 2 / rect.width()

        self.parent.index -= int(pianyi)
        self.parent.index = max(self.parent.index, 60)

        pg.ViewBox.mouseDragEvent(self, ev, axis)
        self.parent.refresh() 
Example #18
Source File: dps_GUI_program.py    From DPS5005_pyGUI with GNU General Public License v3.0 5 votes vote down vote up
def pg_plot_setup(self): # right axis not connected to automatic scaling on the left ('A' icon on bottom LHD)
		self.p1 = self.graphicsView.plotItem
		self.p1.setClipToView(True)     

	# x axis    
		self.p1.setLabel('bottom', 'Time', units='s', color=self.limits.x_colour, **{'font-size':'10pt'})
		self.p1.getAxis('bottom').setPen(pg.mkPen(color=self.limits.x_colour, width=self.limits.x_pen_weight))

	# Y1 axis   
		self.p1.setLabel('left', 'Voltage', units='V', color=self.limits.y1_colour, **{'font-size':'10pt'})
		self.pen_Y1 = pg.mkPen(color=self.limits.y1_colour, width=self.limits.y1_pen_weight)
		self.p1.getAxis('left').setPen(self.pen_Y1)
	
	# setup viewbox for right hand axis
		self.p2 = pg.ViewBox()
		self.p1.showAxis('right')
		self.p1.scene().addItem(self.p2)
		self.p1.getAxis('right').linkToView(self.p2)
		self.p2.setXLink(self.p1)

	# Y2 axis
		self.p1.setLabel('right', 'Current', units="A", color=self.limits.y2_colour, **{'font-size':'10pt'})
		self.pen_Y2 = pg.mkPen(color=self.limits.y2_colour, width=self.limits.y1_pen_weight)
		self.p1.getAxis('right').setPen(self.pen_Y2)
		
	# scales ViewBox to scene
		self.p1.vb.sigResized.connect(self.updateViews) 
Example #19
Source File: qt_plot_area.py    From enamlx with MIT License 5 votes vote down vote up
def _refresh_multi_axis(self):
        """ If linked axis' are used, setup and link them """
        d = self.declaration
        
        #: Create a separate viewbox
        self.viewbox = pg.ViewBox()
        
        #: If this is the first nested plot, use the parent right axis
        _plots = [c for c in self.parent().children() if isinstance(c,AbstractQtPlotItem)]
        i = _plots.index(self)
        if i==0:
            self.axis = self.widget.getAxis('right') 
            self.widget.showAxis('right')
        else:
            self.axis = pg.AxisItem('right')
            self.axis.setZValue(-10000)
            
            #: Add new axis to scene
            self.widget.layout.addItem(self.axis,2,i+2)
        
        #: Link x axis to the parent axis
        self.viewbox.setXLink(self.widget.vb)
        
        #: Link y axis to the view
        self.axis.linkToView(self.viewbox)
        
        #: Set axis label
        self.axis.setLabel(d.label_right)
        
        #: Add Viewbox to parent scene
        self.parent().parent_widget().scene().addItem(self.viewbox) 
Example #20
Source File: MultiplePlotAxes.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def updateViews():
    ## view has resized; update auxiliary views to match
    global p1, p2, p3
    p2.setGeometry(p1.vb.sceneBoundingRect())
    p3.setGeometry(p1.vb.sceneBoundingRect())
    
    ## need to re-update linked axes since this was called
    ## incorrectly while views had different shapes.
    ## (probably this should be handled in ViewBox.resizeEvent)
    p2.linkedViewChanged(p1.vb, p2.XAxis)
    p3.linkedViewChanged(p1.vb, p3.XAxis) 
Example #21
Source File: customPlot.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        self.setMouseMode(self.RectMode)
        
    ## reimplement right-click to zoom out 
Example #22
Source File: customPlot.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 5 votes vote down vote up
def mouseDragEvent(self, ev):
        if ev.button() == QtCore.Qt.RightButton:
            ev.ignore()
        else:
            pg.ViewBox.mouseDragEvent(self, ev) 
Example #23
Source File: graphics.py    From suite2p with GNU General Public License v3.0 5 votes vote down vote up
def mouseDragEvent(self, ev, axis=None):
        ## if axis is specified, event will only affect that axis.
        ev.accept()  ## we accept all buttons

        pos = ev.pos()
        lastPos = ev.lastPos()
        dif = pos - lastPos
        dif = dif * -1

        ## Ignore axes if mouse is disabled
        mouseEnabled = np.array(self.state['mouseEnabled'], dtype=np.float)
        mask = mouseEnabled.copy()
        if axis is not None:
            mask[1-axis] = 0.0

        ## Scale or translate based on mouse button
        if ev.button() & (QtCore.Qt.LeftButton | QtCore.Qt.MidButton):
            if self.state['mouseMode'] == pg.ViewBox.RectMode:
                if ev.isFinish():  ## This is the final move in the drag; change the view scale now
                    #print "finish"
                    self.rbScaleBox.hide()
                    ax = QtCore.QRectF(Point(ev.buttonDownPos(ev.button())), Point(pos))
                    ax = self.childGroup.mapRectFromParent(ax)
                    self.showAxRect(ax)
                    self.axHistoryPointer += 1
                    self.axHistory = self.axHistory[:self.axHistoryPointer] + [ax]
                else:
                    ## update shape of scale box
                    self.updateScaleBox(ev.buttonDownPos(), ev.pos())
            else:
                tr = dif*mask
                tr = self.mapToView(tr) - self.mapToView(Point(0,0))
                x = tr.x() if mask[0] == 1 else None
                y = tr.y() if mask[1] == 1 else None

                self._resetTarget()
                if x is not None or y is not None:
                    self.translateBy(x=x, y=y)
                self.sigRangeChangedManually.emit(self.state['mouseEnabled']) 
Example #24
Source File: MultiplePlotAxes.py    From tf-pose with Apache License 2.0 5 votes vote down vote up
def updateViews():
    ## view has resized; update auxiliary views to match
    global p1, p2, p3
    p2.setGeometry(p1.vb.sceneBoundingRect())
    p3.setGeometry(p1.vb.sceneBoundingRect())
    
    ## need to re-update linked axes since this was called
    ## incorrectly while views had different shapes.
    ## (probably this should be handled in ViewBox.resizeEvent)
    p2.linkedViewChanged(p1.vb, p2.XAxis)
    p3.linkedViewChanged(p1.vb, p3.XAxis) 
Example #25
Source File: customPlot.py    From tf-pose with Apache License 2.0 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        self.setMouseMode(self.RectMode)
        
    ## reimplement right-click to zoom out 
Example #26
Source File: customPlot.py    From tf-pose with Apache License 2.0 5 votes vote down vote up
def mouseDragEvent(self, ev):
        if ev.button() == QtCore.Qt.RightButton:
            ev.ignore()
        else:
            pg.ViewBox.mouseDragEvent(self, ev) 
Example #27
Source File: uiKLine.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        # 拖动放大模式
        #self.setMouseMode(self.RectMode)
        
    ## 右键自适应
    #---------------------------------------------------------------------- 
Example #28
Source File: traceviewer.py    From tridesclous with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        #~ self.disableAutoRange() 
Example #29
Source File: ndscatter.py    From tridesclous with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        self.disableAutoRange()
        self.drag_points = [] 
Example #30
Source File: waveformviewer.py    From tridesclous with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwds):
        pg.ViewBox.__init__(self, *args, **kwds)
        #~ self.disableAutoRange()