2012-04-04 16:22:43 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Tests use of IsoCurve item displayed with image
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import initExample ## Add path to library (just for examples; you do not need this)
|
|
|
|
|
|
|
|
|
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
|
|
|
|
2021-01-27 18:59:07 +00:00
|
|
|
app = pg.mkQApp("Isocurve Example")
|
2012-04-04 16:22:43 +00:00
|
|
|
|
|
|
|
## make pretty looping data
|
|
|
|
frames = 200
|
|
|
|
data = np.random.normal(size=(frames,30,30), loc=0, scale=100)
|
|
|
|
data = np.concatenate([data, data], axis=0)
|
2018-03-30 18:48:05 +00:00
|
|
|
data = pg.gaussianFilter(data, (10, 10, 10))[frames//2:frames + frames//2]
|
2012-12-22 21:51:25 +00:00
|
|
|
data[:, 15:16, 15:17] += 1
|
2012-04-04 16:22:43 +00:00
|
|
|
|
2018-02-16 04:15:32 +00:00
|
|
|
win = pg.GraphicsLayoutWidget(show=True)
|
2013-02-25 04:09:03 +00:00
|
|
|
win.setWindowTitle('pyqtgraph example: Isocurve')
|
2012-04-04 16:22:43 +00:00
|
|
|
vb = win.addViewBox()
|
|
|
|
img = pg.ImageItem(data[0])
|
|
|
|
vb.addItem(img)
|
|
|
|
vb.setAspectLocked()
|
|
|
|
|
|
|
|
## generate empty curves
|
|
|
|
curves = []
|
|
|
|
levels = np.linspace(data.min(), data.max(), 10)
|
|
|
|
for i in range(len(levels)):
|
|
|
|
v = levels[i]
|
|
|
|
## generate isocurve with automatic color selection
|
|
|
|
c = pg.IsocurveItem(level=v, pen=(i, len(levels)*1.5))
|
|
|
|
c.setParentItem(img) ## make sure isocurve is always correctly displayed over image
|
|
|
|
c.setZValue(10)
|
|
|
|
curves.append(c)
|
|
|
|
|
|
|
|
## animate!
|
|
|
|
ptr = 0
|
|
|
|
imgLevels = (data.min(), data.max() * 2)
|
|
|
|
def update():
|
|
|
|
global data, curves, img, ptr, imgLevels
|
|
|
|
ptr = (ptr + 1) % data.shape[0]
|
|
|
|
data[ptr]
|
|
|
|
img.setImage(data[ptr], levels=imgLevels)
|
|
|
|
for c in curves:
|
|
|
|
c.setData(data[ptr])
|
|
|
|
|
|
|
|
timer = QtCore.QTimer()
|
|
|
|
timer.timeout.connect(update)
|
|
|
|
timer.start(50)
|
|
|
|
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
2021-05-13 21:28:22 +00:00
|
|
|
pg.exec()
|