Python - How to plot 'boundary edge' onto a 2D plot
<p>The program <strong>pastebinned</strong> below generates a plot that looks like:
<a href="http://i.stack.imgur.com/6pTzP.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/6pTzP.jpg" alt="Original plot"></a>
<strong>Pastebin</strong>: <a href="http://pastebin.com/wNgAG6K9" rel="nofollow">http://pastebin.com/wNgAG6K9</a> </p>

<p>Basically, the program solves an equation for AA, and plots the values provided AA>0 and AA=/=0. The data is plotted using <code>pcolormesh</code> from 3 arrays called <code>x</code>, <code>y</code> and <code>z</code> (lines 57 - 59).</p>

<p><strong>What I want to do:</strong></p>

<p>I would like to plot a line around the boundary where the solutions go from zero (black) to non-zero (yellow/green), see plot below. What is the most sensible way to go about this? </p>

<p>I.e. lines in red (done crudely in MS paint)</p>

<p><a href="http://i.stack.imgur.com/qHcFZ.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/qHcFZ.jpg" alt="enter image description here"></a></p>

<p><strong>Further info: I need to be able to store the red dashed boundary values so that I can plot the red dashed boundary condition to another 2d plot made from real/measured/non-theoretical data.</strong></p>

<p>Feel free to ask for further information.</p>

<p>Without seeing your data, I would suggest first trying to work with matplotlib's internal algorithm to plot the <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.contour" rel="nofollow"><code>contour</code></a> line corresponding to the zero level. This is simple, but it might happen that the interpolation that is used for this doesn't look good enough (I don't know if it can find that sharp peak in the contour line). The proof of the pudding is in the eating:</p>

<pre><code>plt.contour(x,y,z,[0],colors='r',linewidths=2,linestyles='dashed')
</code></pre>

<p>If that doesn't suffice, you might have to resort to image processing methods to find the boundaries of your data (after turning it into binary).</p>

python matplotlib plot