-
Notifications
You must be signed in to change notification settings - Fork 0
/
eq_world_map.py
41 lines (35 loc) · 1.09 KB
/
eq_world_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
37
38
39
40
41
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)
# Store the data in a dictionary
all_eq_dicts = all_eq_data['features']
# Store the name of the data
plotname = all_eq_data['metadata']['title']
# Locate magnitude data
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': 'Inferno',
'reversescale': True,
'colorbar': {'title': 'Magnitude'},
},
}]
my_layout = Layout(title=f'{plotname}')
fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='global_earthquakes.html')