Commit 9b046dd7 authored by Martin Drechsler's avatar Martin Drechsler

imageview example added

parent 0d88326f
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 22:28:58 2019
@author: martindrech
"""
# -*- coding: utf-8 -*-
"""
Demonstrates very basic use of ImageItem to display image data inside a ViewBox.
"""
## Add path to library (just for examples; you do not need this)
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph as pg
import pyqtgraph.ptime as ptime
def _twoD_gaussian(lim=10, sigma=1, x0=0, y0=0):
N = 600
x, y = np.meshgrid(np.linspace(-lim, lim, N), np.linspace(-lim, lim, N))
d = np.sqrt((x - x0) ** 2 + (y - y0) ** 2)
g = np.exp(-((d) ** 2 / (2.0 * sigma ** 2)))
noise = np.random.normal(size=(N, N))/10
return g + noise
app = QtGui.QApplication([])
## Create window with ImageView widget
win = QtGui.QMainWindow()
win.resize(800,800)
imv = pg.ImageView()
win.setCentralWidget(imv)
win.show()
win.setWindowTitle('pyqtgraph example: ImageView')
## Create random image
data = np.asarray([_twoD_gaussian() for i in range(50)])
i = 0
updateTime = ptime.time()
fps = 0
def updateData():
global img, data, i, updateTime, fps
## Display the data
imv.setImage(data[i], autoHistogramRange=False, autoLevels=False,
autoRange=False
)
i = (i+1) % data.shape[0]
QtCore.QTimer.singleShot(1, updateData)
now = ptime.time()
fps2 = 1.0 / (now-updateTime)
updateTime = now
fps = fps * 0.9 + fps2 * 0.1
#print "%0.1f fps" % fps
updateData()
## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment