1# -*- coding: utf-8 -*- 2""" 3Tests use of IsoCurve item displayed with image 4""" 5 6 7import initExample ## Add path to library (just for examples; you do not need this) 8 9 10from pyqtgraph.Qt import QtGui, QtCore 11import numpy as np 12import pyqtgraph as pg 13 14app = pg.mkQApp("Isocurve Example") 15 16## make pretty looping data 17frames = 200 18data = np.random.normal(size=(frames,30,30), loc=0, scale=100) 19data = np.concatenate([data, data], axis=0) 20data = pg.gaussianFilter(data, (10, 10, 10))[frames//2:frames + frames//2] 21data[:, 15:16, 15:17] += 1 22 23win = pg.GraphicsLayoutWidget(show=True) 24win.setWindowTitle('pyqtgraph example: Isocurve') 25vb = win.addViewBox() 26img = pg.ImageItem(data[0]) 27vb.addItem(img) 28vb.setAspectLocked() 29 30## generate empty curves 31curves = [] 32levels = np.linspace(data.min(), data.max(), 10) 33for i in range(len(levels)): 34 v = levels[i] 35 ## generate isocurve with automatic color selection 36 c = pg.IsocurveItem(level=v, pen=(i, len(levels)*1.5)) 37 c.setParentItem(img) ## make sure isocurve is always correctly displayed over image 38 c.setZValue(10) 39 curves.append(c) 40 41## animate! 42ptr = 0 43imgLevels = (data.min(), data.max() * 2) 44def update(): 45 global data, curves, img, ptr, imgLevels 46 ptr = (ptr + 1) % data.shape[0] 47 data[ptr] 48 img.setImage(data[ptr], levels=imgLevels) 49 for c in curves: 50 c.setData(data[ptr]) 51 52timer = QtCore.QTimer() 53timer.timeout.connect(update) 54timer.start(50) 55 56if __name__ == '__main__': 57 pg.exec() 58