-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2014.py
46 lines (38 loc) · 1 KB
/
2014.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
import numpy as np
import pandas as pd
import plotly
import plotly.graph_objs as go
from plotly.offline import *
df = pd.read_csv('processedyr.csv')
for col in df.columns:
df[col] = df[col].astype(str)
scl = [[0.0, 'rgb(253,224,221)'], [0.5, 'rgb(250,159,181)'],
[1.0, 'rgb(197,27,138)']]
df['text'] = df['state'] + '<br>' +\
'Suicide by gun rate '+df['2014rt']
data = [dict(
type='choropleth',
colorscale=scl,
autocolorscale=False,
locations=df['code'],
z=df['2014rt'].astype(float),
locationmode='USA-states',
text=df['text'],
marker=dict(
line=dict(
color='rgb(255,255,255)',
width=2
)),
colorbar=dict(
title="Suicide by gun rate")
)]
layout = dict(
title='Suicide by gun rate 2014',
geo=dict(
scope='usa',
projection=dict(type='albers usa'),
showlakes=True,
lakecolor='rgb(255, 255, 255)'),
)
fig = dict(data=data, layout=layout)
plotly.offline.plot(fig, filename='2014_map')