Created
July 26, 2022 03:45
-
-
Save naiborhujosua/7d70d6960517701dd4bc5f4c7c1537ea to your computer and use it in GitHub Desktop.
Pie Chart
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
# Draw Plot | |
fig, ax = plt.subplots(figsize=(12, 7), subplot_kw=dict(aspect="equal"), dpi= 80) | |
# Prepare Data | |
df = data.groupby('Seasons').size().reset_index(name='counts') | |
data_df = df['counts'] | |
categories = df['Seasons'] | |
explode = [0,0,0,0.1] | |
def func(pct, allvals): | |
absolute = int(pct/100.*np.sum(allvals)) | |
return "{:.1f}% ({:d} )".format(pct, absolute) | |
wedges, texts, autotexts = ax.pie(data_df, | |
autopct=lambda pct: func(pct, data_df), | |
textprops=dict(color="w"), | |
colors=plt.cm.Dark2.colors, | |
startangle=140, | |
explode=explode) | |
# Decoration | |
ax.legend(wedges, categories, title="Rented Bike Count based on Seasons", loc="center left", bbox_to_anchor=(1, 0, 0.5, 1)) | |
plt.setp(autotexts, size=10, weight=700) | |
ax.set_title("Seasons: Pie Chart") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment