axis labels were hard coded, ignoring value passed in.

Also added docstring to function.
This commit is contained in:
Roger Labbe 2020-10-13 08:46:54 -07:00
parent 01f61bbc4d
commit 2126f9ebc8

View File

@ -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()
display_stddev_plot()