-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathridesBySector.py
65 lines (42 loc) · 1.81 KB
/
ridesBySector.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import seaborn as sns
filename = 'daily_estimates.csv'
daily_estimates = pd.read_csv(filename, header=1, na_values='-')
last_decade_columns = ['Sector', 'Site #', 'Location', '2018', '2017', '2016', '2015',
'2014', '2013', '2012', '2011', '2010', '2009', '2008']
last_decade_estimates = daily_estimates[last_decade_columns]
melted = pd.melt(last_decade_estimates, id_vars=[
'Sector', 'Site #', 'Location'], value_name='rides', var_name='year')
melted.rides = pd.to_numeric(melted.rides, errors='coerce')
melted.Sector = melted.Sector.astype('category')
melted.year = pd.to_datetime(melted.year)
melted.head()
melted_group = melted.groupby(['Sector', 'year']).rides.sum()
df = pd.DataFrame(melted_group).reset_index()
plt.style.use('seaborn-darkgrid')
palette = plt.get_cmap('Dark2')
RIDE_MAX = 17000
num = 0
for sector in df['Sector'].unique():
num += 1
plt.subplot(3, 3, num)
sector_df = df[df['Sector'] == sector]
plt.plot(sector_df['year'], sector_df['rides'], label=sector,
color=palette(num), alpha=0.9, linewidth=1.9)
plt.ylim(0, RIDE_MAX)
if num in range(6):
plt.tick_params(labelbottom='off')
if num not in [1, 4, 7]:
plt.tick_params(labelleft='off')
plt.xticks(rotation=75)
plt.yticks(np.arange(0, RIDE_MAX, step=5000))
plt.title(sector, loc='left', fontsize=12,
fontweight=0, color=palette(num))
plt.suptitle("Portland, Oregon manual 2-hour bike counts",
fontsize=13, fontweight=0, color='black')
plt.gcf().text(0.03, 0.5, 'Daily Estimate',
ha='center', va='center', rotation='vertical')
plt.show()