Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Python, can Matplotlib's Contour function return the points of a particular contour line?

I had to use contour plots to generate plots of a set of inconveniently defined hyperbolic functions. This works and it plots a series of them with some noise added (it's a passive RF geolocation TDOA problem for those who are familiar with such things).

Since my python program knows the (x,y) of the target, I want to sample all the different hyperbolas that I'm drawing around that point and generate an error ellipse. If I can get the Matplotlib contour function to return the points of each contour line as it is drawn, I can handle the rest of the calculations. So...

Can the Matplotlib contour function return all of the (x,y) values for a particular contour line, say at f(x,y)=0?

like image 753
Noise in the street Avatar asked Aug 08 '14 15:08

Noise in the street


1 Answers

You can draw a contour at a specific level like this:

c = plt.contour(X, Y, Z, [level])

Now you can extract the contour points from the returned object c (see this answer):

v = c.collections[0].get_paths()[0].vertices
x = v[:,0]
y = v[:,1]
like image 101
Falko Avatar answered Nov 01 '22 17:11

Falko