Pyplot errorbar keeps connecting my points with lines?

☆樱花仙子☆ 提交于 2021-02-04 13:16:51

问题


I am having trouble getting these lines between my data points to go away! It seems to be whenever I try to add error bars it does this. If you look at the graphs, the first is without the errorbar line, and the second is with it. Is this a usual side effect of pyplot errorbar? Does anyone know why it does this, or how to make it go away?

plt.figure()
plt.scatter(x, y, label = 'blah')
plt.errorbar(x, y, yerr = None, xerr = x_err) 
plt.plot(x, f) #this is a line of best fit


回答1:


You can set the line style (ls) to none:

import numpy as np
import matplotlib.pylab as plt

x = np.arange(10)
y = np.arange(10)
yerr = np.random.random(10)
xerr = np.random.random(10)

plt.figure()
plt.subplot(121)
plt.scatter(x, y, label = 'blah')
plt.errorbar(x, y, yerr = None, xerr = xerr) 

plt.subplot(122)
plt.scatter(x, y, label = 'blah')
plt.errorbar(x, y, yerr = None, xerr = xerr, ls='none') 



来源:https://stackoverflow.com/questions/40020274/pyplot-errorbar-keeps-connecting-my-points-with-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!