[Python] Error bars only getting caps in xerr not yerr despite there not being any xerr

Discussão em 'Python' iniciado por Stack, Maio 1, 2025.

  1. Stack

    Stack Membro Participativo

    Python is adding caps to non-existent error bars while completely ignoring the existing error bars.

    This is my code:

    data = pd.read_excel("Excel_data.xlsx", sheet_name = "avg errors")

    angles = np.array(data.columns)
    data = np.array(data)
    averages = data[0,:]
    errors = data[1,:]

    fig, ax = plt.subplots(subplot_kw={'projection': 'polar'})

    angles = [radians(a) for a in angles]

    ax.plot(angles, averages,markers = 'o', markersize = 3)
    ax.errorbar(angles, averages, fmt = 'none', yerr=errors)
    ax.set_thetamin(-91)
    ax.set_thetamax(91)
    ax.set_theta_offset(3*np.pi/2)
    ax.set_yticks([0,20,40,60,80,100])
    ax.set_yticklabels([0,20,40,60,80,100])
    plt.show()



    Which gives me a great graph:

    [​IMG]

    However, when I try to add caps to the error bars by changing the line specifying the errorbars:

    ax.errorbar(angles, averages, fmt = 'none', yerr=errors, capsize = 10)


    It doesn't add caps to the existing error bars. Instead, it adds error bars to the non-existent error bars in the x direction (as is visible by the slight thickening of the y-error bars near the points): [​IMG]

    Here are arrays with approximate values for each of the datasets:

    angles: [-90 -75 -60 -45 -30 30 45 60 75 90]
    averages: [73 63 57 54 39 39 56 59 62 73]
    errors: [ 7.9 6.4 5.2 4.3 5.6 4.0 3.7 5.5 4.6 12.0]

    Continue reading...

Compartilhe esta Página