[SciPy-user] Getting coordinates of a level (contour) curve

Zachary Pincus zachary.pincus at yale.edu
Tue Aug 12 11:15:58 EDT 2008


Hi all,

It's straightforward to *estimate* the level curves of a function that  
has been evaluated a regularly-spaced grid. (e.g. the "marching cubes"  
algorithm and it's 2D antecedent, "marching squares".) I suspect that  
this is what matplotlib is doing.

I can send a reasonably-fast C implementation of this for the 2D case  
if anyone wants. (GPL or BSD, take your pick.)

Following a level curve from an arbitrary function is a bit harder. If  
you have the function's gradient, you could in theory just go around  
in a direction orthogonal to the gradient, but in the real world that  
wouldn't work with numerical error and finite step sizes. You could  
probably take steps orthogonal to the gradient, then correct back to  
the desired level value by stepping along the gradient, and then  
repeat until you get back near to where you started. This sounds like  
far more trouble than it's worth, but if the function is very  
expensive to evaluate, it might be cheaper and more accurate than  
evaluating the function on a lattice and then estimating the level  
curves from that...

Zach




On Aug 12, 2008, at 10:36 AM, Rob Clewley wrote:

>> Yes, you are right. But what if I have a mixture of gaussians, or any
>> other 2D probability density function?
>
> Indeed. Isn't the question about how to extract the data points for
> the curve from the 'contour' object in matplotlib, in the general
> case? Unfortunately I don't have the answer to that, but maybe
> introspection of the object would lead to an answer. From the API doc
> I see a mysterious attribute called 'level'.
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user




More information about the SciPy-User mailing list