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
|
2011-04-05 16:53:05 +00:00
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
|
2012-03-02 03:53:52 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
2011-04-05 14:35:50 +00:00
|
|
|
import numpy as np
|
|
|
|
import pyqtgraph as pg
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2011-06-14 23:47:52 +00:00
|
|
|
#QtGui.QApplication.setGraphicsSystem('raster')
|
2010-03-22 05:48:52 +00:00
|
|
|
app = QtGui.QApplication([])
|
|
|
|
mw = QtGui.QMainWindow()
|
2011-06-14 23:47:52 +00:00
|
|
|
mw.resize(800,800)
|
2010-03-22 05:48:52 +00:00
|
|
|
cw = QtGui.QWidget()
|
|
|
|
mw.setCentralWidget(cw)
|
|
|
|
l = QtGui.QVBoxLayout()
|
|
|
|
cw.setLayout(l)
|
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
pw = pg.PlotWidget(name='Plot1') ## giving the plots names allows us to link their axes together
|
2010-03-22 05:48:52 +00:00
|
|
|
l.addWidget(pw)
|
2011-04-05 14:35:50 +00:00
|
|
|
pw2 = pg.PlotWidget(name='Plot2')
|
2010-03-22 05:48:52 +00:00
|
|
|
l.addWidget(pw2)
|
2011-04-05 14:35:50 +00:00
|
|
|
pw3 = pg.PlotWidget()
|
2010-03-22 05:48:52 +00:00
|
|
|
l.addWidget(pw3)
|
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
mw.show()
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
## Create an empty plot curve to be filled later, set its pen
|
2010-03-22 05:48:52 +00:00
|
|
|
p1 = pw.plot()
|
2011-04-05 14:35:50 +00:00
|
|
|
p1.setPen((200,200,100))
|
|
|
|
|
|
|
|
## Add in some extra graphics
|
2012-03-02 02:55:32 +00:00
|
|
|
rect = QtGui.QGraphicsRectItem(QtCore.QRectF(0, 0, 1, 5e-11))
|
2010-03-22 05:48:52 +00:00
|
|
|
rect.setPen(QtGui.QPen(QtGui.QColor(100, 200, 100)))
|
|
|
|
pw.addItem(rect)
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
pw.setLabel('left', 'Value', units='V')
|
|
|
|
pw.setLabel('bottom', 'Time', units='s')
|
|
|
|
pw.setXRange(0, 2)
|
|
|
|
pw.setYRange(0, 1e-10)
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
def rand(n):
|
2011-04-05 14:35:50 +00:00
|
|
|
data = np.random.random(n)
|
2010-03-22 05:48:52 +00:00
|
|
|
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
|
2011-04-05 14:35:50 +00:00
|
|
|
data *= 1e-12
|
|
|
|
return data, np.arange(n, n+len(data)) / float(n)
|
2010-03-22 05:48:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
def updateData():
|
|
|
|
yd, xd = rand(10000)
|
2012-03-02 02:55:32 +00:00
|
|
|
p1.setData(y=yd, x=xd)
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
## Start a timer to rapidly update the plot in pw
|
2010-03-22 05:48:52 +00:00
|
|
|
t = QtCore.QTimer()
|
2011-04-05 14:35:50 +00:00
|
|
|
t.timeout.connect(updateData)
|
2010-03-22 05:48:52 +00:00
|
|
|
t.start(50)
|
2012-03-02 02:55:32 +00:00
|
|
|
#updateData()
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2011-04-05 14:35:50 +00:00
|
|
|
## Multiple parameterized plots--we can autogenerate averages for these.
|
2010-03-22 05:48:52 +00:00
|
|
|
for i in range(0, 5):
|
|
|
|
for j in range(0, 3):
|
|
|
|
yd, xd = rand(10000)
|
2011-02-08 00:40:38 +00:00
|
|
|
pw2.plot(y=yd*(j+1), x=xd, params={'iter': i, 'val': j})
|
2011-04-05 14:35:50 +00:00
|
|
|
|
|
|
|
## Test large numbers
|
2012-03-02 02:55:32 +00:00
|
|
|
curve = pw3.plot(np.random.normal(size=100)*1e0, clickable=True)
|
2011-04-05 14:35:50 +00:00
|
|
|
curve.setPen('w') ## white pen
|
|
|
|
curve.setShadowPen(pg.mkPen((70,70,30), width=6, cosmetic=True))
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
def clicked():
|
|
|
|
print "curve clicked"
|
|
|
|
curve.sigClicked.connect(clicked)
|
|
|
|
|
|
|
|
lr = pg.LinearRegionItem([1, 30], bounds=[0,100], movable=True)
|
|
|
|
pw3.addItem(lr)
|
|
|
|
line = pg.InfiniteLine(angle=90, movable=True)
|
|
|
|
pw3.addItem(line)
|
|
|
|
line.setBounds([0,200])
|
2011-04-05 14:35:50 +00:00
|
|
|
|
|
|
|
## Start Qt event loop unless running in interactive mode.
|
|
|
|
if sys.flags.interactive != 1:
|
|
|
|
app.exec_()
|