views:

90

answers:

1

I have an implicit function, for example:

f(x,y) = x**y + y**y - 3*x

I want to solve the root on a meshgrid. So f(x,y) = 0

Drawing the solution is easy:

x = linspace(-2,2,11)
y = linspace(-2,2,11)
(X,Y) = meshgrid(x,y)

A = X**Y + Y**Y - 3*X
contour(X,Y,A,0)

This works great, I have a drawing of the curve I need, however I would like to have the data that is in the plot and not only the visual plot. So how do I find the data of the plot?

+2  A: 

You can get "the data that is in the [matplotlib] plot" using:

cs = contour(X,Y,A,0)
data = cs.collections[0].get_paths()[1]

There are a variety of algorithms for calculating the contours directly, though I don't know of any numpy/scipy versions. Marching squares is the one I always here about, although the algorithm is patented and there are severe restrictions on it's use, so I doubt matplotlib uses it. Here's a link with a bit of chat on how matplotlib calculates the contours.

tom10
I get the following error: IndexError: list index out of rangeWhere do I find this class information. I think I can figure it out myself, but somehow I am unable to find the description of all classes
Enrico
It worked: data = cs.collections[0].get_paths()[0] Thanks a lot, still I would like to know where I find this information myself, could you tell me?
Enrico
OK found that as well: http://matplotlib.sourceforge.net/api/path_api.html
Enrico
Enrico - I'm not sure whether you want more info on this... but how I work stuff like this out is that I use an interactive environment like ipython, and if I want access to things in a plot I start by getting the return value ("cs" here). Then I do "help cs", and look over what's available in cs and go for the most promising ("collections" here), and I just work my way down this way. When I end up with the paths, as here, the docs are right there when I use "help" again.
tom10