a5668a1a26
Implements single axis scaling by mouse wheel over tick marks
72 lines
1.8 KiB
Python
72 lines
1.8 KiB
Python
#!/usr/bin/python
|
|
# -*- coding: utf-8 -*-
|
|
## Add path to library (just for examples; you do not need this)
|
|
import sys, os
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
|
|
|
|
from PyQt4 import QtGui, QtCore
|
|
import numpy as np
|
|
import pyqtgraph as pg
|
|
|
|
app = QtGui.QApplication([])
|
|
mw = QtGui.QMainWindow()
|
|
cw = QtGui.QWidget()
|
|
mw.setCentralWidget(cw)
|
|
l = QtGui.QVBoxLayout()
|
|
cw.setLayout(l)
|
|
|
|
pw = pg.PlotWidget(name='Plot1') ## giving the plots names allows us to link their axes together
|
|
l.addWidget(pw)
|
|
pw2 = pg.PlotWidget(name='Plot2')
|
|
l.addWidget(pw2)
|
|
pw3 = pg.PlotWidget()
|
|
l.addWidget(pw3)
|
|
|
|
mw.show()
|
|
|
|
## Create an empty plot curve to be filled later, set its pen
|
|
p1 = pw.plot()
|
|
p1.setPen((200,200,100))
|
|
|
|
## Add in some extra graphics
|
|
rect = QtGui.QGraphicsRectItem(QtCore.QRectF(0, 0, 1, 1))
|
|
rect.setPen(QtGui.QPen(QtGui.QColor(100, 200, 100)))
|
|
pw.addItem(rect)
|
|
|
|
|
|
def rand(n):
|
|
data = np.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
|
|
data *= 1e-12
|
|
return data, np.arange(n, n+len(data)) / float(n)
|
|
|
|
|
|
def updateData():
|
|
yd, xd = rand(10000)
|
|
p1.updateData(yd, x=xd)
|
|
|
|
## Start a timer to rapidly update the plot in pw
|
|
t = QtCore.QTimer()
|
|
t.timeout.connect(updateData)
|
|
t.start(50)
|
|
|
|
## Multiple parameterized plots--we can autogenerate averages for these.
|
|
for i in range(0, 5):
|
|
for j in range(0, 3):
|
|
yd, xd = rand(10000)
|
|
pw2.plot(y=yd*(j+1), x=xd, params={'iter': i, 'val': j})
|
|
|
|
## Test large numbers
|
|
curve = pw3.plot(np.random.normal(size=100)*1e6)
|
|
curve.setPen('w') ## white pen
|
|
curve.setShadowPen(pg.mkPen((70,70,30), width=6, cosmetic=True))
|
|
|
|
|
|
## Start Qt event loop unless running in interactive mode.
|
|
if sys.flags.interactive != 1:
|
|
app.exec_()
|