path: root/
blob: 36eadc6cab68cca90a5501a62d438e13228e556d (plain) (tree)

# How many tickers are issued in Boston per month?
import matplotlib.pyplot as plt

import pandas as pd
import numpy as np
import utils

months = range(1, 13)
data =

# group all tickets by month
bmo = data.groupby(pd.Grouper(key="Issued", freq="M"))["Issued"].count()
fig, ax = plt.subplots()

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

# group year/month into month
bmo2 = bmo.copy()
bmo2.index =  bmo2.index.strftime("%m")

# plot the average and standard deviation
avg = bmo2.groupby(bmo2.index).median()
# plt.plot(months, avg, color="black", alpha=0.5)

# add standard deviation shading
std = bmo2.groupby(bmo2.index).std()
plt.fill_between(months, avg-std, avg+std, facecolor="white")

# add each month-year total
plt.scatter(bmo.index.month, bmo.values, color="black",
            alpha=0.5, label="11-19")
plt.scatter(covid.index.month, covid.values, color="tab:red",
            alpha=0.5, label="2020")

plt.legend(loc="lower left", framealpha=0.5)
plt.xticks(months, ['J', 'F', 'M', 'A', 'M', 'J',
                    'J', 'A', 'S', 'O', 'N', 'D'])

    title="Tickets Issued in each Month",
    ylabel="Tickets Issued")

    utils.FIG_DIR / "tickets-per-month.svg",