From 573d5bf4a975baef4293fc51e2419e6f8fba5d0a Mon Sep 17 00:00:00 2001 From: BaoGiang HoangVu Date: Mon, 26 Oct 2020 20:09:14 +0700 Subject: [PATCH 1/3] extend linear regression lines to the entire length of plots in Anscombe's Quartet example --- examples/specialty_plots/anscombe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/specialty_plots/anscombe.py b/examples/specialty_plots/anscombe.py index 30e880882942..f033f717f10c 100644 --- a/examples/specialty_plots/anscombe.py +++ b/examples/specialty_plots/anscombe.py @@ -41,7 +41,7 @@ # linear regression p1, p0 = np.polyfit(x, y, deg=1) - x_lin = np.array([np.min(x), np.max(x)]) + x_lin = np.array([0, 20]) y_lin = p1 * x_lin + p0 ax.plot(x_lin, y_lin, 'r-', lw=2) From 1531619e7d21fdb119f5ca23194016ca94bbc5c9 Mon Sep 17 00:00:00 2001 From: BaoGiang HoangVu Date: Mon, 26 Oct 2020 22:22:17 +0700 Subject: [PATCH 2/3] draw regression lines with `axline` --- examples/specialty_plots/anscombe.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/specialty_plots/anscombe.py b/examples/specialty_plots/anscombe.py index f033f717f10c..e1442d063c2e 100644 --- a/examples/specialty_plots/anscombe.py +++ b/examples/specialty_plots/anscombe.py @@ -40,10 +40,8 @@ ax.plot(x, y, 'o') # linear regression - p1, p0 = np.polyfit(x, y, deg=1) - x_lin = np.array([0, 20]) - y_lin = p1 * x_lin + p0 - ax.plot(x_lin, y_lin, 'r-', lw=2) + p1, p0 = np.polyfit(x, y, deg=1) # slope, intercept + ax.axline(xy1=(0, p0), slope=p1, color='r', lw=2) # add text box for the statistics stats = (f'$\\mu$ = {np.mean(y):.2f}\n' From 191b7b2f506a73baeffb9217e02860014a0cce8b Mon Sep 17 00:00:00 2001 From: BaoGiang HoangVu Date: Mon, 26 Oct 2020 23:10:11 +0700 Subject: [PATCH 3/3] add references --- examples/specialty_plots/anscombe.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples/specialty_plots/anscombe.py b/examples/specialty_plots/anscombe.py index e1442d063c2e..93390907f7b3 100644 --- a/examples/specialty_plots/anscombe.py +++ b/examples/specialty_plots/anscombe.py @@ -52,3 +52,18 @@ transform=ax.transAxes, horizontalalignment='right') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.axline +matplotlib.axes.Axes.text +matplotlib.axes.Axes.tick_params