Removing zigzag line joining data in matplotlib
<p>I am plotting using the matplotlib.pyplot plot() method:</p>

<pre><code>import matplotlib.pyplot as plt
import matplotlib
#matplotlib.style.use('ggplot')

plt.plot(df_both_grouped['TSD_mean'], df_both_grouped['hgd_mean'], 'or', color = 'blue')
plt.errorbar(df_both_grouped['TSD_mean'], df_both_grouped['hgd_mean'], yerr = df_both_grouped['TSD_err'], xerr = df_both_grouped['home_goal_err'], color = 'blue')
</code></pre>

<p>Everything works great except I cannot seem to get rid of the annoying zigzag line that connects my points (example below).</p>

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

<p>N.B: There is an additional fitting line I wish to keep. I didn't add the code for brevity.</p>

<p>Is there an argument that I need to add/remove? I am sure this is a simple issue, but it is driving me insane ;)</p>

<p>Thanks in advance!</p>

<p>You are looking for the <em>fmt</em> argument of the <em>errorbar</em> method.</p>

<p>Simply change your code to</p>

<pre><code>import matplotlib.pyplot as plt
import matplotlib
#matplotlib.style.use('ggplot')

plt.plot(df_both_grouped['TSD_mean'], df_both_grouped['hgd_mean'], 'or', color = 'blue')
plt.errorbar(df_both_grouped['TSD_mean'], df_both_grouped['hgd_mean'], yerr = df_both_grouped['TSD_err'], xerr = df_both_grouped['home_goal_err'], color = 'blue', fmt='None')
</code></pre>

<p>to get rid of the connection lines as documented <a href="http://matplotlib.org/1.2.1/api/axes_api.html?highlight=errorbar#matplotlib.axes.Axes.errorbar" rel="nofollow">here (errorbar)</a>.</p>

<p>Actually, you can also use the <em>linestyle</em> or <em>ls</em> argument (comming from the resutling <a href="http://matplotlib.org/1.2.1/api/artist_api.html#matplotlib.lines.Line2D" rel="nofollow">Line2D</a> object), like with the ordinary plot command.</p>

<pre><code>plt.errorbar(df_both_grouped['TSD_mean'], df_both_grouped['hgd_mean'], yerr = df_both_grouped['TSD_err'], xerr = df_both_grouped['home_goal_err'], color = 'blue', ls='None')
</code></pre>

python matplotlib plot