PyQwt
Qwt and PyQwt exists for both Linux/Unix and Windows. Qwt is
a set of plotting widgets. Installing these is currently not
quite as comfortable as installing numpy, but the instructions
in the package are excellent:
boud@calcifer:~/src > tar -xzf qwt-0.3.0.tar.gz
boud@calcifer:~/src > cd qwt-0.3.0
boud@calcifer:~/src/qwt-0.3.0 > ls
CHANGES COPYING CVS doc Doxyfile Doxyfile.users examples
include INSTALL makefiles propagate qwt.pro README
README.QT src
boud@calcifer:~/src/qwt-0.3.0 > cp makefiles/linux-g++ ./Makefile
boud@calcifer:~/src/qwt-0.3.0 > make
...
ln -s libqwt.so.0.3.0 libqwt.so
ln -s libqwt.so.0.3.0 libqwt.so.0
ln -s libqwt.so.0.3.0 libqwt.so.0.3
boud@calcifer:~/src/qwt-0.3.0 > nc README
boud@calcifer:~/src/qwt-0.3.0 > su
Password:
root@calcifer:/home/boud/src/qwt-0.3.0 > mv libqwt.* /usr/local/lib
root@calcifer:/home/boud/src/qwt-0.3.0 > mkdir /usr/local/include/qwt
This did the trick—at least on my system! Now you just
have to instal the Python bindings. This is even easier, since
PyQwt now uses Distutils to get itself installed. However, note
that you need to have a source installation
of PyQt if you intend to build PyQwt from source. There are
currently binary packages for Windows and some versions of
Linux, like Mandrake.
PyQwt has a number of illustrative demo scripts—here, I
picked one to demonstrate to you the way it works.
#!/usr/bin/env python
#
# qwtdemo.py
#
# Demonstrates that you can plot NumPy arrays and lists of Python floats.
# NumPy arrays are more elegant and more than 20 times faster than lists.
import sys
from qt import *
from qwt import *
from Numeric import *
def drange(start, stop, step):
start, stop, step = float(start), float(stop), float(step)
size = int(round((stop-start)/step))
result = [start]*size
for i in xrange(size):
result[i] += i*step
return result
def lorentzian(x):
return 1.0/(1.0+(x-5.0)**2)
class ListArrayDemo(QWidget):
def __init__(self, *args):
apply(QWidget.__init__, (self,) + args)
# create a plot widget for NumPy arrays
self.aplot = QwtPlot('Plot -- NumPy arrays', self)
# calculate 2 NumPy arrays
xa = arange(0.0, 10.0, 0.01)
ya = lorentzian(xa)
# insert a curve, make it red and copy the arrays
ca = self.aplot.insertCurve('y = lorentzian(x)')
self.aplot.setCurvePen(ca, QPen(Qt.red))
self.aplot.setCurveData(ca, xa, ya)
# create a plot widget for lists of Python floats
self.lplot = QwtPlot('Plot -- List of Python floats', self)
# calculate 2 lists of Python floats
xl = drange(0.0, 10.0, 0.01)
yl = map(lorentzian, xl)
# insert a curve, make it blue and copy the lists
cl = self.lplot.insertCurve('y = lorentzian(x)')
self.lplot.setCurvePen(cl, QPen(Qt.blue))
self.lplot.setCurveData(cl, xl, yl)
def resizeEvent(self, e):
x = e.size().width()
y = e.size().height()/2
self.aplot.resize(x, y)
self.aplot.move(0, 0)
self.lplot.resize(x, y)
self.lplot.move(0, y)
# admire
app = QApplication(sys.argv)
demo = ListArrayDemo()
app.setMainWidget(demo)
demo.resize(400, 600)
demo.show()
app.exec_loop()
As you can see, the core of the Qwt library is the
QwtPlot widget - an object that knows how
to plot, but can be used as any other Qt widget.