Search code examples
pythonmatplotlibseabornerrorbar

Add error bars manually to seaborn line marker plots


I have columns of x, mean and std. I want to plot line with markers of using seaborn:

import seaborn as sns
import matplotlib.pyplot as plt

x = [0,1,2]
mean = [2,1,3]
std = [0.1,0.4,0.2]

sns.lineplot(x=x,y=mean,marker='o')

How to add std as errorbars?


Solution

  • I found an answer that works for me:

    df = pd.DataFrame({'x':x,'y':mean,'std':std})
    
    g = sns.FacetGrid(df, size=5)
    g.map(plt.errorbar, "x", "y", "std", marker="o")
    

    plot