1# -*- coding: utf-8 -*- 2""" 3Demonstrates use of FillBetweenItem to fill the space between two plot curves. 4""" 5import initExample ## Add path to library (just for examples; you do not need this) 6 7import pyqtgraph as pg 8from pyqtgraph.Qt import QtGui, QtCore 9import numpy as np 10 11#FIXME: When running on Qt5, not as perfect as on Qt4 12 13win = pg.plot() 14win.setWindowTitle('pyqtgraph example: FillBetweenItem') 15win.setXRange(-10, 10) 16win.setYRange(-10, 10) 17 18N = 200 19x = np.linspace(-10, 10, N) 20gauss = np.exp(-x**2 / 20.) 21mn = mx = np.zeros(len(x)) 22curves = [win.plot(x=x, y=np.zeros(len(x)), pen='k') for i in range(4)] 23brushes = [0.5, (100, 100, 255), 0.5] 24fills = [pg.FillBetweenItem(curves[i], curves[i+1], brushes[i]) for i in range(3)] 25for f in fills: 26 win.addItem(f) 27 28def update(): 29 global mx, mn, curves, gauss, x 30 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.01 35 mn = np.where(y1<mn, y1, mn) * (1-s) + y1 * s 36 mx = np.where(y2>mx, y2, mx) * (1-s) + y2 * s 37 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