Aluode/PerceptionLabPortable
0
1"""2This example demonstrates many of the 2D plotting capabilities3in pyqtgraph. All of the plots may be panned/scaled by dragging with 4the left/right mouse buttons. Right click on any plot to show a context menu.5"""6 7import numpy as np8 9import pyqtgraph as pg10from pyqtgraph.Qt import QtCore11 12app = pg.mkQApp("Plotting Example")13#mw = QtWidgets.QMainWindow()14#mw.resize(800,800)15 16win = pg.GraphicsLayoutWidget(show=True, title="Basic plotting examples")17win.resize(1000,600)18win.setWindowTitle('pyqtgraph example: Plotting')19 20# Enable antialiasing for prettier plots21pg.setConfigOptions(antialias=True)22 23p1 = win.addPlot(title="Basic array plotting", y=np.random.normal(size=100))24 25p2 = win.addPlot(title="Multiple curves")26p2.plot(np.random.normal(size=100), pen=(255,0,0), name="Red curve")27p2.plot(np.random.normal(size=110)+5, pen=(0,255,0), name="Green curve")28p2.plot(np.random.normal(size=120)+10, pen=(0,0,255), name="Blue curve")29 30p3 = win.addPlot(title="Drawing with points")31p3.plot(np.random.normal(size=100), pen=(200,200,200), symbolBrush=(255,0,0), symbolPen='w')32 33 34win.nextRow()35 36p4 = win.addPlot(title="Parametric, grid enabled")37x = np.cos(np.linspace(0, 2*np.pi, 1000))38y = np.sin(np.linspace(0, 4*np.pi, 1000))39p4.plot(x, y)40p4.showGrid(x=True, y=True)41 42p5 = win.addPlot(title="Scatter plot, axis labels, log scale")43x = np.random.normal(size=1000) * 1e-544y = x*1000 + 0.005 * np.random.normal(size=1000)45y -= y.min()-1.046mask = x > 1e-1547x = x[mask]48y = y[mask]49p5.plot(x, y, pen=None, symbol='t', symbolPen=None, symbolSize=10, symbolBrush=(100, 100, 255, 50))50p5.setLabel('left', "Y Axis", units='A')51p5.setLabel('bottom', "Y Axis", units='s')52p5.setLogMode(x=True, y=False)53 54p6 = win.addPlot(title="Updating plot")55curve = p6.plot(pen='y')56data = np.random.normal(size=(10,1000))57ptr = 058def update():59 global curve, data, ptr, p660 curve.setData(data[ptr%10])61 if ptr == 0:62 p6.enableAutoRange('xy', False) ## stop auto-scaling after the first data set is plotted63 ptr += 164timer = QtCore.QTimer()65timer.timeout.connect(update)66timer.start(50)67 68 69win.nextRow()70 71p7 = win.addPlot(title="Filled plot, axis disabled")72y = np.sin(np.linspace(0, 10, 1000)) + np.random.normal(size=1000, scale=0.1)73p7.plot(y, fillLevel=-0.3, brush=(50,50,200,100))74p7.showAxis('bottom', False)75 76 77x2 = np.linspace(-100, 100, 1000)78data2 = np.sin(x2) / x279p8 = win.addPlot(title="Region Selection")80p8.plot(data2, pen=(255,255,255,200))81lr = pg.LinearRegionItem([400,700])82lr.setZValue(-10)83p8.addItem(lr)84 85p9 = win.addPlot(title="Zoom on selected region")86p9.plot(data2)87def updatePlot():88 p9.setXRange(*lr.getRegion(), padding=0)89def updateRegion():90 lr.setRegion(p9.getViewBox().viewRange()[0])91lr.sigRegionChanged.connect(updatePlot)92p9.sigXRangeChanged.connect(updateRegion)93updatePlot()94 95if __name__ == '__main__':96 pg.exec()97 