diff --git a/examples/specialty_plots/anscombe.py b/examples/specialty_plots/anscombe.py index 30e880882942..93390907f7b3 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([np.min(x), np.max(x)]) - 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' @@ -54,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