Add Regression Line In The Scatter Matrix Of Pandas
I've found a lot of news on this subject, but no one has made my case. I have a quite large dataframe where I would like to add the regression line and on the opposite side of the
Solution 1:
The simplest way would be to use seaborn's PairGrid
:
from scipy.stats import pearsonr
defreg_coef(x,y,label=None,color=None,**kwargs):
ax = plt.gca()
r,p = pearsonr(x,y)
ax.annotate('r = {:.2f}'.format(r), xy=(0.5,0.5), xycoords='axes fraction', ha='center')
ax.set_axis_off()
iris = sns.load_dataset("iris")
g = sns.PairGrid(iris)
g.map_diag(sns.distplot)
g.map_lower(sns.regplot)
g.map_upper(reg_coef)
Post a Comment for "Add Regression Line In The Scatter Matrix Of Pandas"