Python - Qwt
Appearance
Install
Windows
In order to use the plot lib PyQwt I installed the following packages:
- Python 2.6.2(14MB)
- Python-QT4 Lib for GUIs 4.5.4-1 (18MB) (No separate install of QT necessary)
- Numpy 1.3 used for list manipulating needed by PyQwt
- PyQwt 5.2.0 Plot Lib
- iPython interactive python terminal
- readline (needed by iPython)
Unfortunately above Python installer does not add python to the windows search path, so you have to do it by hand:
- right mouse button on
- EN: My Computer -> Properties -> Advanced -> Environment Variables -> System Variables -> Path
- DE: Arbeitsplatz -> Eigenschaften -> Erweitert -> Umgebungsvariablen -> Systemvariablen -> Path
add "c:\python26;" at the beginning of this line
Simple Plot Class Example
# for plotting we use Qwt5
import PyQt4.Qwt5 as Qwt
# QT stuff
from PyQt4 import Qt
class myPlot(Qwt.QwtPlot):
def __init__(self):
Qwt.QwtPlot.__init__(self)
# Initialize data
self.x = []
self.y = []
self.y2 = []
self.setCanvasBackground(Qt.Qt.white)
self.plotLayout().setCanvasMargin(0)
self.plotLayout().setAlignCanvasToScales(True)
#self.insertLegend(Qwt.QwtLegend(), Qwt.QwtPlot.BottomLegend);
# axes
self.setAxisTitle(Qwt.QwtPlot.xBottom, "x (a.u.)")
self.setAxisTitle(Qwt.QwtPlot.yLeft, "y (a.u.)")
self.enableAxis(Qwt.QwtPlot.yRight)
self.setAxisTitle(Qwt.QwtPlot.yRight, "y2 (a.u.)")
# legend
legend = Qwt.QwtLegend()
#self.insertLegend(legend, Qwt.QwtPlot.RightLegend)
self.insertLegend(legend, Qwt.QwtPlot.BottomLegend)
# grid
grid = Qwt.QwtPlotGrid()
pen = Qt.QPen(Qt.Qt.DotLine)
pen.setColor(Qt.Qt.black)
pen.setWidth(0)
grid.setPen(pen)
grid.attach(self)
# curves
self.curve = Qwt.QwtPlotCurve("Data y")
self.curve.setYAxis(Qwt.QwtPlot.yLeft)
self.curve.setPen(Qt.QPen(Qt.Qt.red))
self.curve.setSymbol(Qwt.QwtSymbol(
Qwt.QwtSymbol.Ellipse,
Qt.QBrush(),
Qt.QPen(Qt.Qt.red),
Qt.QSize(7, 7)))
self.curve.attach(self)
self.curve2 = Qwt.QwtPlotCurve("Data y")
self.curve2.setYAxis(Qwt.QwtPlot.yLeft)
self.curve2.setPen(Qt.QPen(Qt.Qt.blue))
self.curve2.setSymbol(Qwt.QwtSymbol(Qwt.QwtSymbol.Ellipse,
Qwt.QwtSymbol.Ellipse,
Qt.QBrush(),
Qt.QPen(Qt.Qt.blue),
Qt.QSize(7, 7)))
self.curve2.attach(self)
def plotValues(self, x, y,y2):
self.x.append(x)
self.y.append(y)
self.y2.append(y2)
self.curve.setData(self.x, self.y)
self.curve2.setData(self.x, self.y2)
self.replot()
def clear(self):
self.x = []
self.y = []
self.y2 = []
self.curve.setData(self.x, self.y)
self.curve2.setData(self.x, self.y2)
self.replot()
def setATitle(self, axis, title): # axis = x,y,y2
title = ""+title+"" # you may want this to be a bigger value...
if axis == "x" :
self.setAxisTitle(Qwt.QwtPlot.xBottom, title)
elif axis == "y" :
self.setAxisTitle(Qwt.QwtPlot.yLeft, title)
elif axis == "y2" :
self.setAxisTitle(Qwt.QwtPlot.yRight, title)
else :
return 0