user14094230
user14094230

Reputation:

Add custom error bars to seaborn regplot and residplot

Is there a way to add custom error bars to seaborn regplot and residplot like one can do with matplotlib errorbar using yerr? Examples are here; if I just add a yerr argument an error occurs,

import seaborn as sns

xd = [1,2,3,4,6,7]
yd = [2,4,7,9,12,14]
yerrd = [1,2,1,3,1,4]

sns.regplot(xd, yd)

sns.residplot(xd, yd)

Upvotes: 1

Views: 2869

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40697

Draw the errorbars using matplotlib's errorbar

xd = [1,2,3,4,6,7]
yd = [2,4,7,9,12,14]
yerrd = [1,2,1,3,1,4]
fig, ax = plt.subplots()
sns.regplot(xd, yd, ax=ax)
ax.errorbar(xd, yd, yerr=yerrd, fmt='none', capsize=5, zorder=1, color='C0')

enter image description here

Upvotes: 3

Related Questions