CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
FillBetweenItem.py50 linesDownload Raw Back to examples
1"""2Demonstrates use of FillBetweenItem to fill the space between two plot curves.3"""4 5import numpy as np6 7import pyqtgraph as pg8from pyqtgraph.Qt import QtCore9 10#FIXME: When running on Qt5, not as perfect as on Qt411 12win = pg.plot()13win.setWindowTitle('pyqtgraph example: FillBetweenItem')14win.setXRange(-10, 10)15win.setYRange(-10, 10)16 17N = 20018x = np.linspace(-10, 10, N)19gauss = np.exp(-x**2 / 20.)20mn = mx = np.zeros(len(x))21curves = [win.plot(x=x, y=np.zeros(len(x)), pen='k') for i in range(4)]22brushes = [0.5, (100, 100, 255), 0.5]23fills = [pg.FillBetweenItem(curves[0], curves[3], brushes[0]),24         pg.FillBetweenItem(curves[1], curves[2], brushes[1])]25for f in fills:26    win.addItem(f)27 28def update():29    global mx, mn, curves, gauss, x30    a = 5 / abs(np.random.normal(loc=1, scale=0.2))31    y1 = -np.abs(a*gauss + np.random.normal(size=len(x)))32    y2 =  np.abs(a*gauss + np.random.normal(size=len(x)))33    34    s = 0.0135    mn = np.where(y1<mn, y1, mn) * (1-s) + y1 * s36    mx = np.where(y2>mx, y2, mx) * (1-s) + y2 * s37    curves[0].setData(x, mn)38    curves[1].setData(x, y1)39    curves[2].setData(x, y2)40    curves[3].setData(x, mx)41    42 43timer = QtCore.QTimer()44timer.timeout.connect(update)45timer.start(30)46 47 48if __name__ == '__main__':49    pg.exec()50 
Aluode/PerceptionLabPortable · CoolFace