> the first points of the segments are given by the vectors
> (x1,y1) the second (x2,y2). you can get pretty lines in
> matplotlib as well, but only by using the scattered line
> drawing methods of gtk. (something like
> self.area.window.draw_segments(self.gc, zip( x1,y1,x2,y2)?)
OK, I see. I didn't fully understand that x1,x2,y1,y2 were the verts
of unordered line segments. Then one can easily use a LineCollection
to draw these efficiently in matplotlib - script below and screenshot
http://nitace.bsd.uchicago.edu:8080/files/share/kontour.png. Jeez, I
feel bad for sitting on this since February!
> if you want do do it "right" in matplotlib, you should
> implement a contour following algorithm (in C) - with this
> I mean an routine that returns the linesegments defining
> each countour in bundles. the current alg. is sort of
> marching cubes in 2D, a simplified version of CONREC
> http://astronomy.swin.edu.au/~pbourke/projection/conrec/
> but only using 2 triangles per square.
Do you have any thoughts on how we might do labels with your code?
> doing contour following alg. it is also much easier to
> implement automatic contour labelling. I suspect python
> loops are too slow for such algorithms - it may perhaps be
> possible to do them in Numeric, but it will still be much
> slower than my simple library. I think you may use the
> GPL'ed PLPLOT (C) for an example of contour following alg.
We have a problem in that we cannot use GPL'd code in matplotlib
because the GPL does not allow redistribution of closed code, which
the matplotlib (and python license) do.
If we decide to go with your routines, at least for the time being
until we can "do it right", would you be willing to contribute your
code to matplotlib under the matplotlib license (PSF inspired, free
for commercial and noncommercial reuse)?
Thanks!
JDH
from matplotlib.matlab import *
from matplotlib.collections import LineCollection
import hutil
delta = 0.05
x = y = arange(-3.0, 3.0, delta)
X, Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
Z = Z2-Z1
print Z.shape
fsm = ones(Z.shape, Z.typecode())
zmax, zmin = hutil.maxmin(Z)
depths=linspace(zmin, zmax, 10)
x1,y1,x2,y2 = hutil.contour2(Z, fsm, depths )
imshow(Z, origin='lower', interpolation='nearest')
segments = [ ( (thisy1, thisx1), (thisy2, thisx2) )
for thisx1, thisy1, thisx2, thisy2 in zip( x1,y1,x2,y2)]
coll = LineCollection(segments)
gca().add_collection(coll)
savefig('kontour')
show()