[Python] Aligning error bars to bar in seanborn barplot

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

  1. Stack

    Stack Membro Participativo

    I'm relatively new to python and trying align error bars for cancer data.

    I have a cancer dataset with the following code:

    plt.figure(figsize=(16, 6))

    # Using the barplot method with error bars
    g = sns.barplot(data=dfpp5, x='Type', y='survival', palette=colours, hue='Groups',
    hue_order=hue_order, ci=None)

    # Adding error bars
    for i, row in dfpp5.iterrows():
    plt.errorbar(x=i, y=row['survival'],
    yerr=[[row['survival'] - row['lower']], [row['upper'] - row['survival']]],
    fmt='none', # 'none' to show only error bars
    capsize=5, color='black')


    I've tried looking on here for a solution can't seem to find anything, can anyone resolve. The output i get is

    enter image description here

    Continue reading...

Compartilhe esta Página