Created
April 29, 2020 11:14
-
-
Save cereniyim/6f14a323209b4df5a5caaf2e94326b24 to your computer and use it in GitHub Desktop.
plot histogram with mean and median
This file contains 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
def plot_histogram(df, column, b=None): | |
# funtion to print histogram | |
# with mean and median | |
# using distplot | |
# set the histogram, mean and median | |
g = sns.distplot(df[column], kde=False, bins=b) | |
plt.axvline(x=df[column].mean(), | |
linewidth=3, | |
color='g', | |
label="mean", | |
alpha=0.5) | |
plt.axvline(x=df[column].median(), | |
linewidth=3, | |
color='y', | |
label="median", | |
alpha=0.5) | |
# set title, legends and labels | |
plt.xlabel("{}".format(column), size=14) | |
plt.ylabel("Count", size=14) | |
plt.title("Distribution of {}".format(column), size=16) | |
plt.legend(["mean", "median"]) | |
return g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment