import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.Point import Point

class OtherWindow(QtGui.QMainWindow):
        
    def __init__(self):
                
        QtGui.QMainWindow.__init__(self)
        win = pg.GraphicsLayoutWidget()
        sa = 
QtGui.QScrollArea()                                                             
                                                                   

        sa.setWidgetResizable(True)
        sa.setWidget(win)
        self.setCentralWidget(sa)
        self.setWindowTitle("Plotting")
        
        label = pg.LabelItem(justify='right')
        win.addItem(label)
        p1 = win.addPlot(row=1, col=0)
        p2 = win.addPlot(row=2, col=0)

        region = pg.LinearRegionItem()
        region.setZValue(10)
        
        p2.addItem(region, ignoreBounds=True)

        
        p1.setAutoVisible(y=True)


        data1 = 10000 + 15000 * 
pg.gaussianFilter(np.random.random(size=10000), 10) + 3000 * 
np.random.random(size=10000)
        data2 = 15000 + 15000 * 
pg.gaussianFilter(np.random.random(size=10000), 10) + 3000 * 
np.random.random(size=10000)

        p1.plot(data1, pen="r")
        p1.plot(data2, pen="g")

        p2.plot(data1, pen="w")

        def update():
            region.setZValue(10)
            minX, maxX = region.getRegion()
            p1.setXRange(minX, maxX, padding=0)    

        region.sigRegionChanged.connect(update)

        def updateRegion(window, viewRange):
            rgn = viewRange[0]
            region.setRegion(rgn)

        p1.sigRangeChanged.connect(updateRegion)

        region.setRegion([1000, 2000])

        #cross hair
        vLine = pg.InfiniteLine(angle=90, movable=False)
        hLine = pg.InfiniteLine(angle=0, movable=False)
        p1.addItem(vLine, ignoreBounds=True)
        p1.addItem(hLine, ignoreBounds=True)


        vb = p1.vb

        def mouseMoved(evt):
            pos = evt[0]  ## using signal proxy turns original arguments 
into a tuple
            if p1.sceneBoundingRect().contains(pos):
                mousePoint = vb.mapSceneToView(pos)
                index = int(mousePoint.x())
                if index > 0 and index < len(data1):
                    label.setText("<span style='font-size: 12pt'>x=%0.1f,   
<span style='color: red'>y1=%0.1f</span>,   <span style='color: 
green'>y2=%0.1f</span>" % (mousePoint.x(), data1[index], data2[index]))
                vLine.setPos(mousePoint.x())
                hLine.setPos(mousePoint.y())



        proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60, 
slot=mouseMoved)

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication([])
    myOtherWindow = OtherWindow()
    myOtherWindow.show()
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtGui.QApplication.instance().exec_()

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/656761dc-249d-41f9-98b5-8a282424c34d%40googlegroups.com.

Reply via email to