Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1531619

Browse files
draw regression lines with axline
1 parent 573d5bf commit 1531619

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

examples/specialty_plots/anscombe.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,8 @@
4040
ax.plot(x, y, 'o')
4141

4242
# linear regression
43-
p1, p0 = np.polyfit(x, y, deg=1)
44-
x_lin = np.array([0, 20])
45-
y_lin = p1 * x_lin + p0
46-
ax.plot(x_lin, y_lin, 'r-', lw=2)
43+
p1, p0 = np.polyfit(x, y, deg=1) # slope, intercept
44+
ax.axline(xy1=(0, p0), slope=p1, color='r', lw=2)
4745

4846
# add text box for the statistics
4947
stats = (f'$\\mu$ = {np.mean(y):.2f}\n'

0 commit comments

Comments
 (0)