views:

124

answers:

2

Hello everybody,

Is there an easy way to get the (x,y) values of a contour line that was plotted like this:

import matplotlib.pyplot as plt
x = [1,2,3,4]
y = [1,2,3,4]
m = [[15,14,13,12],[14,12,10,8],[13,10,7,4],[12,8,4,0]]
cs = plt.contour(x,y,m, [9.5])
plt.show()

Cheers, Philipp

A: 

You can place the mouse pointer over the line plotted and in the bottom right of the plotting window will show the x, y coordinates.

Here are several good examples with code of putting values on the plot:

http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/contour%5Fdemo.html

http://matplotlib.sourceforge.net/examples/pylab%5Fexamples/contourf%5Fdemo.html

I hope that helps.

Casey
+4  A: 

Look at the collections property of the returned ContourSet. In particular the get_paths() method of the first collection returns paired points making up each line segment.

cs.collections[0].get_paths()
Mark