Skip to content

Instantly share code, notes, and snippets.

@cereniyim
Created April 29, 2020 11:14
Show Gist options
  • Save cereniyim/6f14a323209b4df5a5caaf2e94326b24 to your computer and use it in GitHub Desktop.
Save cereniyim/6f14a323209b4df5a5caaf2e94326b24 to your computer and use it in GitHub Desktop.
plot histogram with mean and median
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