matplotlib.pyplot errorbar ValueError depends on array length?
Question: Good afternoon.

I've been struggling with this for a while now, and although I can find
similiar problems online, nothing I found could really help me resolve it.

Starting with a standard data file (.csv or .txt, I tried both) containing
three columns (x, y and the error of y), I want to read in the data and
generate a line plot including error bars.

I can plot the x and y values without a problem, but if I want to add
errorbars using the matplotlib.pyplot errorbar utility, I get the following
error message:

`ValueError: yerr must be a scalar, the same dimensions as y, or 2xN.`

The code below works if I use some arbitrary arrays (numpy or plain python),
but not for data read from the file. I've tried converting the tuples which I
obtain from my input code to numpy arrays using asarray, but to no avail.

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    row = []
    with open("data.csv") as data:
        for line in data:
            row.append(line.split(','))
    
    column = zip(*row)
    
    x = column[0] 
    y = column[1]
    yer = column[2]
    
    plt.figure() 
    plt.errorbar(x,y,yerr = yer)
    
    fig = plt.gcf()
    fig.set_size_inches(18.5, 10.5)
    fig.savefig('example.png', dpi=300)
    

It must be that I am overlooking something. I would be very grateful for any
thoughts on the matter.


Answer: `yerr` should be the added/subtracted error from the `y` value. In your case
the added equals the subtracted equals half of the third column.

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    data = np.loadtxt('data.csv', delimiter=',')
    
    plt.figure()
    yerr_ = np.tile(data[:, 2]/2, (2, 1))
    plt.errorbar(data[:, 0], data[:, 1], yerr=yerr_)
    plt.xlim([-1, 3])
    plt.show()
    

data.csv

    
    
    0,2,0.3
    1,4,0.4
    2,3,0.15
    

