Skip to content

Instantly share code, notes, and snippets.

@naiborhujosua
Created July 26, 2022 03:45
Show Gist options
  • Save naiborhujosua/68e97d072bfea0c04cc688a6aa8b442f to your computer and use it in GitHub Desktop.
Save naiborhujosua/68e97d072bfea0c04cc688a6aa8b442f to your computer and use it in GitHub Desktop.
from scipy.stats import sem
# Import Data
data_mean = data.groupby('Hour')["Rented Bike Count"].mean()
data_se = data.groupby('Hour')["Rented Bike Count"].apply(sem).mul(1.96)
# Plot
plt.figure(figsize=(16,10), dpi= 80)
plt.ylabel("# Hours", fontsize=16)
x = data_mean.index
plt.plot(x, data_mean, color="white", lw=2)
plt.fill_between(x, data_mean - data_se, data_mean + data_se, color="#3F5D7D")
# Decorations
# Lighten borders
plt.gca().spines["top"].set_alpha(0)
plt.gca().spines["bottom"].set_alpha(1)
plt.gca().spines["right"].set_alpha(0)
plt.gca().spines["left"].set_alpha(1)
plt.xticks(x[::2], [str(d) for d in x[::2]] , fontsize=12)
plt.title("User Orders by Hour of Day (95% confidence)", fontsize=22)
plt.xlabel("Hour of Day")
s, e = plt.gca().get_xlim()
plt.xlim(s, e)
# Draw Horizontal Tick lines
for y in range(8, 20, 2):
plt.hlines(y, xmin=s, xmax=e, colors='black', alpha=0.5, linestyles="--", lw=0.5)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment