-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStates_Heatmap.py
97 lines (89 loc) · 2.82 KB
/
States_Heatmap.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# import matplotlib.pyplot as plt
# from matplotlib.cm import get_cmap
import json
import csv
'''
x = list(range(1,12))
y = [1]*11
colors = list(range(0,10)) + [398]
# cmap = 'cool', 'jet', 'rainbow'
plt.scatter(x, y, s=200, c=colors, cmap="jet")
cbar = plt.colorbar(orientation="vertical")
plt.show()
cmap = get_cmap('jet')
rgba = cmap(0.5)
print(rgba)
'''
states = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
'AS': 'American Samoa',
'AZ': 'Arizona',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DC': 'District of Columbia',
'DE': 'Delaware',
'FL': 'Florida',
'GA': 'Georgia',
'GU': 'Guam',
'HI': 'Hawaii',
'IA': 'Iowa',
'ID': 'Idaho',
'IL': 'Illinois',
'IN': 'Indiana',
'KS': 'Kansas',
'KY': 'Kentucky',
'LA': 'Louisiana',
'MA': 'Massachusetts',
'MD': 'Maryland',
'ME': 'Maine',
'MI': 'Michigan',
'MN': 'Minnesota',
'MO': 'Missouri',
'MP': 'Commonwealth of the Northern Mariana Islands',
'MS': 'Mississippi',
'MT': 'Montana',
'NA': 'National',
'NC': 'North Carolina',
'ND': 'North Dakota',
'NE': 'Nebraska',
'NH': 'New Hampshire',
'NJ': 'New Jersey',
'NM': 'New Mexico',
'NV': 'Nevada',
'NY': 'New York',
'OH': 'Ohio',
'OK': 'Oklahoma',
'OR': 'Oregon',
'PA': 'Pennsylvania',
'PR': 'Puerto Rico',
'RI': 'Rhode Island',
'SC': 'South Carolina',
'SD': 'South Dakota',
'TN': 'Tennessee',
'TX': 'Texas',
'UT': 'Utah',
'VA': 'Virginia',
'VI': 'United States Virgin Islands',
'VT': 'Vermont',
'WA': 'Washington',
'WI': 'Wisconsin',
'WV': 'West Virginia',
'WY': 'Wyoming'
}
with open("User_Analysis/User_States.json", "r") as fp:
states_dict = json.load(fp)
state_colors = [['Shape Name', 'User Count']]
for key, value in states_dict.items():
'''
color = cmap(float(value)/398)
color = (round(color[0]*255), round(color[1]*255), round(color[2]*255))
state_colors.append([states[key], '#{:02X}{:02X}{:02X}'.format(*color)])
'''
state_colors.append([states[key], value])
with open("User_Analysis/User_State_Distribution.csv", "w", newline='') as f:
writer = csv.writer(f)
writer.writerows(state_colors)
print("File successfully saved. . .")