-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
70 lines (61 loc) · 1.61 KB
/
Copy pathplot.py
File metadata and controls
70 lines (61 loc) · 1.61 KB
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
import plotly
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv('large_cities.csv')
df.head()
df['text'] = df['name'] + '<br>Risk ' + df['risk'].astype(str) + ' per mln'
fig = go.Figure()
fig.add_trace(go.Scattergeo(
locationmode = 'USA-states',
lon = df['lon'],
lat = df['lat'],
text = df['text'],
marker = dict(
size = df['risk'] * (10 ** 12),
color = 'crimson',
line_color='rgb(40,40,40)',
line_width=0.5,
sizemode = 'area'
),
name = 'High risk cities'))
sf = pd.read_csv('small_cities.csv')
sf.head()
sf['text'] = sf['name'] + '<br>Risk ' + sf['risk'].astype(str) + ' per mln'
fig.add_trace(go.Scattergeo(
locationmode = 'USA-states',
lon = sf['lon'],
lat = sf['lat'],
text = sf['text'],
marker = dict(
size = 5,
color = 'orange',
line_color='rgb(40,40,40)',
line_width=0.5,
sizemode = 'area'
),
name = 'Low risk cities'))
fig.update_layout(
title_text = 'US cities infection risk<br>(Click legend to toggle traces)',
showlegend = True,
geo = dict(
scope = 'usa',
landcolor = 'rgb(217, 217, 217)',
)
)
plotly.offline.plot(fig, filename='us_risks.html')
#fig.show()
'''
with open('map_data.txt') as map_file:
lines = map_file.readlines()
cities = []
risks = []
lats = []
lngs = []
for line in lines:
city, risk, lat, lng = line.split(',')
cities.append(city)
risks.append(float(risk))
lats.append(float(lat))
lng = lng.replace('\n','')
lngs.append(float(lng))'''