Skip to content

Commit 8d2e360

Browse files
authored
Merge pull request #18814 from baogianghoangvu/anscombes-quartet
[Example] update Anscombe's Quartet
2 parents 06514d2 + 191b7b2 commit 8d2e360

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

examples/specialty_plots/anscombe.py

Lines changed: 17 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([np.min(x), np.max(x)])
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'
@@ -54,3 +52,18 @@
5452
transform=ax.transAxes, horizontalalignment='right')
5553

5654
plt.show()
55+
56+
#############################################################################
57+
#
58+
# ------------
59+
#
60+
# References
61+
# """"""""""
62+
#
63+
# The use of the following functions, methods, classes and modules is shown
64+
# in this example:
65+
66+
import matplotlib
67+
matplotlib.axes.Axes.axline
68+
matplotlib.axes.Axes.text
69+
matplotlib.axes.Axes.tick_params

0 commit comments

Comments
 (0)