-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplotly-map.py
36 lines (30 loc) · 1.1 KB
/
plotly-map.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
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv(
'OpioidDeathsAll-cleaned-3.csv')
for col in df.columns:
df[col] = df[col].astype(str)
df['text'] = df['state'] + '<br>' + \
'2014 - ' + df['2014_Number_of_Deaths'] + '<br>' + '2015 - ' + df['2015_Number_of_Deaths'] + '<br>' + '2016 - ' + df['2016_Number_of_Deaths'] + \
'<br>' + '2017 - ' + df['2017_Number_of_Deaths'] + '<br>' + '2018 - ' + \
df['2018_Number_of_Deaths'] + '<br>' + \
'2019 - ' + df['2019_Number_of_Deaths']
fig = go.Figure(data=go.Choropleth(
locations=df['code'],
z=df['total_deaths'].astype(float),
locationmode='USA-states',
colorscale='Reds',
autocolorscale=False,
text=df['text'], # hover text
marker_line_color='white', # line markers between states
))
fig.update_layout(
title_text='Opioid Deaths by State from 2014-2019<br>(Hover for breakdown)',
geo=dict(
scope='usa',
projection=go.layout.geo.Projection(type='albers usa'),
showlakes=True, # lakes
lakecolor='rgb(255, 255, 255)'),
)
fig.show()
fig.write_html("index.html")