Skip to content

Instantly share code, notes, and snippets.

@AO8
Created March 26, 2019 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AO8/7d155e67dc832d465d093d069d09d170 to your computer and use it in GitHub Desktop.
Save AO8/7d155e67dc832d465d093d069d09d170 to your computer and use it in GitHub Desktop.
Fine-tuning matplotlib bar plot of Calendly appointment data. Ongoing Python 3 project.
import csv
import calendar
from collections import Counter
import matplotlib.pyplot as plt
# set up empty Counter objectS
months_counter = Counter()
# open and read CSV
with open("dashboard-export.csv") as f:
csv_reader = csv.DictReader(f)
for row in csv_reader:
items = row["Start Date & Time"].split("/")
m = int(items[0])
months_counter[m] += 1
# sort Counter into dict
months_dict = dict(sorted(months_counter.items()))
# extract appointment date into two lists
months = [key for key in months_dict.keys()]
values = [value for value in months_dict.values()]
# prepare bar graph
plt.style.use("seaborn")
fig, ax = plt.subplots()
plt.xticks(months, calendar.month_name[1:13], rotation=20)
plot = ax.bar(months, values, color="#28a745")
# display data value on head of each bar
for rect in plot:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width() / 2, 1.002 * height,
f"{int(height)}", ha="center", va="bottom")
# add ylim, y axis label and title
ax.set_ylim(0, 60)
ax.set_ylabel("No. of Appointments Booked")
plt.title("Snapshot of BAS-SD advising appts booked with AO: July 2017 to PRESENT",
size="large", weight="bold")
# plot!
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment