summaryrefslogtreecommitdiffstats
path: root/tickets-per-year.py
blob: 8eb2f715b55c10b7dcf558e6768813ae94bbb922 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# How many tickets are issued in Boston per year
#
import matplotlib.patheffects as pe
import matplotlib.pyplot as plt

import pandas as pd
import numpy as np
import utils

data = utils.data

byr = data.groupby(pd.Grouper(key="Issued", freq="Y"))["Issued"].count()
#byr.describe()

# Dropping 2020 as an outlier
byr19 = byr.drop(pd.Timestamp('20201231'))
#byr19.describe()

fig, ax = plt.subplots()
plt.bar(x=byr.index.year, height=byr.values, color="black")

# fit trend line (excluding 2020 data)
fit = np.poly1d(np.polyfit(byr19.index.year, byr19.values, 1))
plt.plot(byr.index.year, fit(byr.index.year), color='tab:red', lw=3)

ax.set(
    title="Tickets Issued per Year",
    ylabel="Tickets Issued (Million)")

plt.savefig(
    utils.FIG_DIR / "tickets-per-year.svg",
    transparent=True)