Created
February 6, 2022 22:07
-
-
Save cwindolf/872012d6594051fb0894c1d7a1480a47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def regline(x, y, ax=None, **kwargs): | |
b = ((x - x.mean()) * (y - y.mean())).sum() / np.square(x - x.mean()).sum() | |
a = y.mean() - b * x.mean() | |
x0, x1 = ax.get_xlim() | |
r = np.corrcoef(x, y)[0, 1] | |
ax.plot([x0, x1], [a + b * x0, a + b * x1], lw=1) | |
ax.text( | |
0.1, | |
0.9, | |
f"$\\rho={r:.2f}$", | |
horizontalalignment="left", | |
verticalalignment="center", | |
transform=ax.transAxes, | |
fontsize=6, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment