From: John H. <jdh...@ac...> - 2004-10-01 16:04:34
|
>>>>> "Helge" == Helge Avlesen <av...@ii...> writes: Helge> http://www.ii.uib.no/~avle/mpl/c1.png Helge> the first points of the segments are given by the vectors Helge> (x1,y1) the second (x2,y2). you can get pretty lines in Helge> matplotlib as well, but only by using the scattered line Helge> drawing methods of gtk. (something like Helge> 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! Helge> if you want do do it "right" in matplotlib, you should Helge> implement a contour following algorithm (in C) - with this Helge> I mean an routine that returns the linesegments defining Helge> each countour in bundles. the current alg. is sort of Helge> marching cubes in 2D, a simplified version of CONREC Helge> http://astronomy.swin.edu.au/~pbourke/projection/conrec/ Helge> but only using 2 triangles per square. Do you have any thoughts on how we might do labels with your code? Helge> doing contour following alg. it is also much easier to Helge> implement automatic contour labelling. I suspect python Helge> loops are too slow for such algorithms - it may perhaps be Helge> possible to do them in Numeric, but it will still be much Helge> slower than my simple library. I think you may use the Helge> 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() |