2010-03-22 05:48:52 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2010-03-22 06:21:56 +00:00
|
|
|
## Add path to library (just for examples; you do not need this)
|
|
|
|
import sys, os
|
|
|
|
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
from scipy import random
|
|
|
|
from PyQt4 import QtGui, QtCore
|
2010-03-22 06:21:56 +00:00
|
|
|
from pyqtgraph.GraphicsView import *
|
|
|
|
from pyqtgraph.graphicsItems import *
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
app = QtGui.QApplication([])
|
|
|
|
mw = QtGui.QMainWindow()
|
|
|
|
cw = QtGui.QWidget()
|
|
|
|
vl = QtGui.QVBoxLayout()
|
|
|
|
cw.setLayout(vl)
|
|
|
|
mw.setCentralWidget(cw)
|
|
|
|
mw.show()
|
|
|
|
mw.resize(800, 600)
|
|
|
|
|
|
|
|
|
|
|
|
gv = GraphicsView(cw)
|
|
|
|
gv.enableMouse(False)
|
|
|
|
l = QtGui.QGraphicsGridLayout()
|
|
|
|
l.setHorizontalSpacing(0)
|
|
|
|
l.setVerticalSpacing(0)
|
|
|
|
|
|
|
|
|
|
|
|
vb = ViewBox()
|
|
|
|
p1 = PlotCurveItem()
|
|
|
|
vb.addItem(p1)
|
|
|
|
vl.addWidget(gv)
|
|
|
|
rect = QtGui.QGraphicsRectItem(QtCore.QRectF(0, 0, 1, 1))
|
|
|
|
rect.setPen(QtGui.QPen(QtGui.QColor(100, 200, 100)))
|
|
|
|
vb.addItem(rect)
|
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
l.addItem(vb, 0, 1)
|
2010-03-22 05:48:52 +00:00
|
|
|
gv.centralWidget.setLayout(l)
|
|
|
|
|
|
|
|
|
|
|
|
xScale = ScaleItem(orientation='bottom', linkView=vb)
|
2010-03-22 06:21:56 +00:00
|
|
|
l.addItem(xScale, 1, 1)
|
2010-03-22 05:48:52 +00:00
|
|
|
yScale = ScaleItem(orientation='left', linkView=vb)
|
2010-03-22 06:21:56 +00:00
|
|
|
l.addItem(yScale, 0, 0)
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
xScale.setLabel(text=u"<span style='color: #ff0000; font-weight: bold'>X</span> <i>Axis</i>", units="s")
|
|
|
|
yScale.setLabel('Y Axis', units='V')
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
def rand(n):
|
|
|
|
data = random.random(n)
|
|
|
|
data[int(n*0.1):int(n*0.13)] += .5
|
|
|
|
data[int(n*0.18)] += 2
|
|
|
|
data[int(n*0.1):int(n*0.13)] *= 5
|
|
|
|
data[int(n*0.18)] *= 20
|
|
|
|
return data, arange(n, n+len(data)) / float(n)
|
|
|
|
|
|
|
|
|
|
|
|
def updateData():
|
|
|
|
yd, xd = rand(10000)
|
|
|
|
p1.updateData(yd, x=xd)
|
|
|
|
|
|
|
|
yd, xd = rand(10000)
|
|
|
|
updateData()
|
|
|
|
vb.autoRange()
|
|
|
|
|
|
|
|
t = QtCore.QTimer()
|
|
|
|
QtCore.QObject.connect(t, QtCore.SIGNAL('timeout()'), updateData)
|
|
|
|
t.start(50)
|
|
|
|
|
2010-03-22 06:21:56 +00:00
|
|
|
app.exec_()
|