From 2126f9ebc852dba28abfdf2e0a565fc72f6fb276 Mon Sep 17 00:00:00 2001 From: Roger Labbe Date: Tue, 13 Oct 2020 08:46:54 -0700 Subject: [PATCH] Issue #352 axis labels were hard coded, ignoring value passed in. Also added docstring to function. --- kf_book/gaussian_internal.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/kf_book/gaussian_internal.py b/kf_book/gaussian_internal.py index 09dd2aa..6ac3e2b 100644 --- a/kf_book/gaussian_internal.py +++ b/kf_book/gaussian_internal.py @@ -40,13 +40,27 @@ def plot_height_std(x, lw=10): def plot_correlated_data(X, Y, xlabel=None, ylabel=None, equal=True): + """Plot correlation between x and y by performing + linear regression between X and Y. + + X: x data + Y: y data + xlabel: str + optional label for x axis + ylabel: str + optional label for y axis + equal: bool, default True + use equal scale for x and y axis + """ + + plt.scatter(X, Y) if xlabel is not None: - plt.xlabel('Height (in)'); + plt.xlabel(xlabel); if ylabel is not None: - plt.ylabel('Weight (lbs)') + plt.ylabel(ylabel) # fit line through data m, b = np.polyfit(X, Y, 1) @@ -115,4 +129,4 @@ def display_stddev_plot(): ax.grid(None, 'both', lw=0) if __name__ == '__main__': - display_stddev_plot() \ No newline at end of file + display_stddev_plot()