summaryrefslogtreecommitdiffstats
path: root/tickets-per-month.py
blob: 36eadc6cab68cca90a5501a62d438e13228e556d (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
# 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 = utils.data
#data.info()

# 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'])

ax.set(
    title="Tickets Issued in each Month",
    ylabel="Tickets Issued")

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