Created
November 21, 2019 05:16
-
-
Save kperry2215/59e435a6c790c7f03b6dd2d4ab2ad6b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
def generate_distribution_histogram(dataframe, | |
column_name, | |
title, x_axis_label, y_axis_label, | |
label_name, | |
number_bins = 15): | |
""" | |
This function generates a histogram. | |
Args: | |
dataframe: | |
column_name: String. Name of the column whose distribution we | |
want to visualize. | |
title: String. Title of the histogram. | |
x_axis_label: String. X-axis label. | |
y_axis_label: String. Y-axis label. | |
Outputs: | |
Histogram containing distribution for specific column column_name. | |
""" | |
plt.hist(dataframe[column_name], bins = number_bins, label = label_name) | |
plt.title(title) | |
plt.xlabel(x_axis_label) | |
plt.ylabel(y_axis_label) | |
plt.legend(loc='upper right') | |
#### MAIN FUNCTION #### | |
generate_distribution_histogram(df, 'age', | |
title = 'Age Distribution: US Population', | |
x_axis_label = 'Age (years)', | |
y_axis_label = 'Frequency', | |
label_name = 'Age') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment