Add r2 to seaborn subplots

Viewed 101
from scipy import stats
import scipy as sp

g = sns.lmplot(data=df, x='fpw_n', y='AI_PEKEL10_r', hue='River', col="River",
             col_wrap=4, height=3,
             sharex = True, sharey = True,
              )

def annotate(data, **kws):
    r, p = sp.stats.pearsonr(data['fpw_n'], data['AI_PEKEL10_r'])
    ax = plt.gca()
    ax.text(.05, .8, 'r={:.2f}, p={:.2g}'.format(r, p),
            transform=ax.transAxes)
    
g.map_dataframe(annotate(df))

plt.show()

I am trying to show r2 on each subplots. The codes worked before based on Seaborn implot with equation and R2 text. However, it returns error now. It seems map_dataframe part is wrong. Anyone can guide me?

0 Answers
Related