Search code examples
pythonmatplotlibplotgraphline

Even after incorporating " linespace = 'None' " in my code, the lines joining up points on graph have not gone away


Trying to rid my graph of the lines that join up the points in order to use my own line of best fit. I have used linespace='None' within my code for plotting the points. Very confused as to why the lines are still there after running the code again.

Any help will be greatly appreciated.

x_a = np.array(x)    #defining x and y variables
y_a = np.array(y)

plt.errorbar(x, y, yerr = data)     #plotting  errorbars

plt.plot(x,y, ls='')      #plotting x and y. Attempting to get rid of lines with ls=''

plt.show

Solution

  • The lines are still coming from the plt.errorbar. Use ls='' for both

    plt.errorbar(x, y, yerr=data, ls='')
    plt.plot(x,y, ls='') 
    

    As pointed out by @DavidG in the comments, plt.plot(x,y, ls='') serves no purpose if you hide the lines. Instead, you can use a scatter plot in addition to the errorbar to show data points as

    plt.scatter(x,y)