-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheq_world_map.py
45 lines (38 loc) · 1.2 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
42
43
44
45
import json
from plotly.graph_objs import Layout
from plotly import offline
# Изучение структуры данных
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:
mag = eq_dict['properties']['mag']
lon = eq_dict['geometry']['coordinates'][0]
lat = eq_dict['geometry']['coordinates'][1]
title = eq_dict['properties']['title']
mags.append(mag)
lons.append(lon)
lats.append(lat)
hover_texts.append(title)
# Нанесение данных на карту
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='Global Earthquakes')
fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='global_earthquakes.html')