 <p>you can use mask array:</p> <pre><code>import numpy as np a=np.array([1,2,3,4,5,6,7,8,9]) b=np.array([-1,-2,-3,-4,-5,1,2,-3,-4]) plot(a, b) m = b &gt; 0 plot(np.ma.array(a, mask=m), np.ma.array(b, mask=m), 'r--', lw=2) </code></pre> <p><img src="https://i.stack.imgur.com/6d3oW.png" alt="enter image description here"></p> <p>However, I think this maybe not what you want. Here is a quick method that can split the lines into two parts:</p> <pre><code>import numpy as np a=np.array([1,2,3,4,5,6,7,8,9]) b=np.array([-1,-2,-3,-4,-5,1,2,-3,-4]) x = np.linspace(a.min(), a.max(), 1000) y = np.interp(x, a, b) m = y &lt;= 0 plot(np.ma.array(x, mask=m), np.ma.array(y, mask=m), 'b-', lw=2) m = y &gt; 0 plot(np.ma.array(x, mask=m), np.ma.array(y, mask=m), 'r--', lw=2) </code></pre> <p><img src="https://i.stack.imgur.com/p4ftX.png" alt="enter image description here"></p> <p><code>np.interp()</code> will use many memory for large dataset, here is another method that find all zero points. The output is the same as above.</p> <pre><code>idx1 = np.where(b[1:] * b[:-1] &lt; 0)[0] idx2 = idx1 + 1 x0 = a[idx1] + np.abs(b[idx1] / (b[idx2] - b[idx1])) * (a[idx2] - a[idx1]) a2 = np.insert(a, idx2, x0) b2 = np.insert(b, idx2, 0) m = b2 &lt; 0 plot(np.ma.array(a2, mask=m), np.ma.array(b2, mask=m), 'b-', lw=2) m = b2 &gt; 0 plot(np.ma.array(a2, mask=m), np.ma.array(b2, mask=m), 'r--', lw=2) </code></pre>