Skip to content

Instantly share code, notes, and snippets.

@naiborhujosua
Created July 26, 2022 03:40
Show Gist options
  • Save naiborhujosua/a32c891725acb84c773e162a603421c7 to your computer and use it in GitHub Desktop.
Save naiborhujosua/a32c891725acb84c773e162a603421c7 to your computer and use it in GitHub Desktop.
Lollipop Bar Chart
df = data[['Rented Bike Count', 'Seasons']].groupby('Seasons').apply(lambda x: x.mean())
df.sort_values('Rented Bike Count', inplace=True)
df.reset_index(inplace=True)
# Draw plot
fig, ax = plt.subplots(figsize=(16,10), dpi= 80)
ax.vlines(x=df.index, ymin=0, ymax=df['Rented Bike Count'], color='firebrick', alpha=0.7, linewidth=2)
ax.scatter(x=df.index, y=df['Rented Bike Count'], s=80, color='firebrick', alpha=0.7)
# Title, Label, Ticks and Ylim
ax.set_title('Lollipop Chart for Rented Bike Count', fontdict={'size':20})
ax.set_ylabel('Rented Bike Count')
ax.set_xticks(df.index)
ax.set_xticklabels(df.Seasons.str.upper(), rotation=60, fontdict={'horizontalalignment': 'right', 'size':12})
ax.set_ylim(0, 1200)
# Annotate Text
for i, rbc in enumerate(df['Rented Bike Count']):
ax.text(i, rbc+3, round(rbc, 1), horizontalalignment='center',verticalalignment='bottom', fontsize=12)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment