-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheq_world_map.py
More file actions
42 lines (34 loc) · 1.11 KB
/
Copy patheq_world_map.py
File metadata and controls
42 lines (34 loc) · 1.11 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
import json
from plotly.graph_objs import Scattergeo, Layout
from plotly import offline
# explore the structure of the data
filename = 'data/eq_data_30_day_m1.json'
with open(filename) as f:
all_eq_data = json.load(f)
readable_file = 'data/readable_eq_data.json'
with open(readable_file, 'w') as f:
json.dump(all_eq_data, f, indent=4)
all_eq_dicts = all_eq_data['features']
mags, lons, lats, hover_texts = [], [], [], []
for eq_dict in all_eq_dicts:
mags.append(eq_dict['properties']['mag'])
lons.append(eq_dict['geometry']['coordinates'][0])
lats.append(eq_dict['geometry']['coordinates'][1])
hover_texts.append(eq_dict['properties']['title'])
# map the earthquakes
data = [{
'type':'scattergeo',
'lon':lons,
'lat':lats,
'text': hover_texts,
'marker': {
'size':[5*mag for mag in mags],
'color':mags,
'colorscale':'Viridis',
'reversescale': True,
'colorbar': {'title':'Magnitude'}
},
}]
my_layout = Layout(title=all_eq_data['metadata']['title'])
fig = {'data':data, 'layout':my_layout}
offline.plot(fig, filename='global_eathquakes.html')