pyqtgraph/examples/ImageItem.py
Luke Campagnola 45048467b3 - Major reorganization; we now follow the standard python package structure.
- Overhaul of SVG export system. Seems to work well.
- Fixed image export bugs
- Added basic 3D line plot class
2012-12-26 17:51:52 -05:00

60 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
## Add path to library (just for examples; you do not need this)
import initExample
from pyqtgraph.Qt import QtCore, QtGui
import numpy as np
import pyqtgraph as pg
import pyqtgraph.ptime as ptime
app = QtGui.QApplication([])
## Create window with GraphicsView widget
view = pg.GraphicsView()
view.show() ## show view alone in its own window
## Allow mouse scale/pan. Normally we use a ViewBox for this, but
## for simple examples this is easier.
view.enableMouse()
## lock the aspect ratio so pixels are always square
view.setAspectLocked(True)
## Create image item
img = pg.ImageItem(border='w')
view.scene().addItem(img)
## Set initial view bounds
view.setRange(QtCore.QRectF(0, 0, 600, 600))
## Create random image
data = np.random.normal(size=(15, 600, 600), loc=1024, scale=64).astype(np.uint16)
i = 0
updateTime = ptime.time()
fps = 0
def updateData():
global img, data, i, updateTime, fps
## Display the data
img.setImage(data[i])
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_()