0

Trying to plot a scatter plot with error bars in Seaborn from data in a pandas dataframe, and conditionally color points if they are not in the confidence interval of the other axis. Here is the code so far:

sns.lmplot(x='reg', y='rd_diff',data = lreg_2016, fit_reg=False)
plt.errorbar(lreg_2016['reg'].values, lreg_2016['rd_diff'].values, yerr= lreg_2016['conf'].values,fmt='o', markersize=4)
plt.show()

enter image description here

What I want is something of a conditional like this:

if lreg_2016['rd_diff'].values > (lreg_2016['reg'].values + lreg_2016['conf'].values) or
    lreg_2016['rd_diff'].values < (lreg_2016['reg'].values - lreg_2016['conf'].values):
        color of point = 'red'

Thanks!

Flow Nuwen
  • 547
  • 5
  • 20
  • Similar idea, although I am asking how to do this specifically with the Seaborn library. – Flow Nuwen Nov 26 '16 at 19:41
  • The solution given in the linked post is independent of any plotting library. It uses conditioned array indexing in numpy and is applicable to any plotting library that can handle numpy arrays. Your `lreg_2016['rd_diff'].values` are numpy arrays, so you just have to copy it. – ImportanceOfBeingErnest Nov 26 '16 at 19:49

0 Answers0