fa6a09d39b71b24217a2c76e0f2fcbbe26664a84 — Bryan Brattlof 2 years ago 1f08e57
add code to generate tickets by day-of-week graphic
1 files changed, 45 insertions(+), 0 deletions(-)

A tickets-per-day-of-week.py
A tickets-per-day-of-week.py => tickets-per-day-of-week.py +45 -0
@@ 0,0 1,45 @@
# How many tickets are issued in Boston per day of week?
import matplotlib.pyplot as plt

import pandas as pd
import numpy as np
import utils

data = utils.data

# group all tickets by day of week
bdow = data.groupby(pd.Grouper(key="Issued", freq="D"))["Issued"].count()
fig, ax = plt.subplots()

# drop 2020 data
covid = bdow[bdow.index.year == 2020]
bdow.drop(covid.index, inplace=True)

# plot the median and average tickets issued per day of week
med = bdow.groupby(bdow.index.dayofweek).median()
std = bdow.groupby(bdow.index.dayofweek).std()

# add median +- standard deviation
plt.fill_between(range(7), med-std, med+std, facecolor="white")
# plt.plot(range(7), med, color="black")

# plot each total for that day (2020 in red)
plt.scatter(x=covid.index.dayofweek, y=covid, color="tab:red",
            alpha=0.2, label="2020")
plt.scatter(x=bdow.index.dayofweek, y=bdow, color="black",
            alpha=0.2, label="11-19")

plt.xticks(range(7), ["Mon", "Tue", "Wen", "Thu", "Fri", "Sat", "Sun"])
plt.legend(loc="upper right")

    title="Tickets Issued on each Day",
    ylabel="Tickets Issued")

    utils.FIG_DIR / "tickets-by-day-of-week.svg",