Note that there are some explanatory texts on larger screens.

plurals
  1. POmatplotlib - extracting data from contour lines
    text
    copied!<p>I would like to get data from a single contour of evenly spaced 2D data (an image-like data).</p> <p>Based on the example found in a similar question: <a href="https://stackoverflow.com/q/1560424/429795">How can I get the (x,y) values of the line that is ploted by a contour plot (matplotlib)?</a> </p> <pre><code>&gt;&gt;&gt; import matplotlib.pyplot as plt &gt;&gt;&gt; x = [1,2,3,4] &gt;&gt;&gt; y = [1,2,3,4] &gt;&gt;&gt; m = [[15,14,13,12],[14,12,10,8],[13,10,7,4],[12,8,4,0]] &gt;&gt;&gt; cs = plt.contour(x,y,m, [9.5]) &gt;&gt;&gt; cs.collections[0].get_paths() </code></pre> <p>The result of this call into <code>cs.collections[0].get_paths()</code> is:</p> <pre><code>[Path([[ 4. 1.625 ] [ 3.25 2. ] [ 3. 2.16666667] [ 2.16666667 3. ] [ 2. 3.25 ] [ 1.625 4. ]], None)] </code></pre> <p>Based on the plots, this result makes sense and appears to be collection of (y,x) pairs for the contour line. </p> <p>Other than manually looping over this return value, extracting the coordinates and assembling arrays for the line, are there better ways to get data back from a <code>matplotlib.path</code> object? Are there pitfalls to be aware of when extracting data from a <code>matplotlib.path</code>?</p> <p>Alternatively, are there alternatives within <code>matplotlib</code> or better yet <code>numpy</code>/<code>scipy</code> to do a similar thing? Ideal thing would be to get a high resolution vector of (x,y) pairs describing the line, which could be used for further analysis, as in general my datasets are not a small or simple as the example above.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload