summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Brattlof <hello@bryanbrattlof.com>2021-02-08 18:19:27 -0500
committerBryan Brattlof <hello@bryanbrattlof.com>2021-02-10 16:12:49 -0500
commit9395830ddbccdebb201ccd42c992c14347d96cfe (patch)
treeff0780861df759b67b9dcd7d1c0b49a8bdf90034
parent7c4875976c49d95f4f8869697c2bf41c9d0962e1 (diff)
downloadboston-parking-tickets-9395830ddbccdebb201ccd42c992c14347d96cfe.tar.gz
boston-parking-tickets-9395830ddbccdebb201ccd42c992c14347d96cfe.tar.bz2
add code to generate tickets per month figure
-rw-r--r--tickets-per-month.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tickets-per-month.py b/tickets-per-month.py
new file mode 100644
index 0000000..36eadc6
--- /dev/null
+++ b/tickets-per-month.py
@@ -0,0 +1,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)