【发布时间】:2021-08-29 08:04:56
【问题描述】:
我想使用 Plotly 在世界地图上可视化地震发生区域。我想通过访问经度和纬度来提供世界地图上大致位置的描述。 我还想看看世界上最严重的地震发生在哪里,我试图通过根据震级改变标记的大小来显示地震的严重程度。
我现在不想拥有 pandas 模块,因为我还没有学过它们。我不知道代码有什么问题,它在浏览器上显示为空白。我处于初学者阶段,所以请尽可能简单地建议我。
代码:
import json
from plotly.graph_objs import Scattergeo, Layout
from plotly import offline
# Explore the structure of the data.
filename = 'Datasets/eq_data_30_day_m1.json'
with open(filename) as f:
all_eq_data = json.load(f)
# Extracting all the important key features.
all_eq_dicts = all_eq_data['features']
# Extracting the magnitude and the locations.
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)
# 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='Global Earthquakes')
fig = {'data': data, 'layout': my_layout}
offline.plot(fig, filename='global_earthquakes.html')
【问题讨论】:
-
抱歉给您添麻烦了,这实际上是我在这里的第一个问题,感谢您指出。
标签: python plotly data-analysis