问题描述
我正在使用 data from the submarinecablemap.com Github repo 在 Plotly 中制作正交投影图。我可以根据 Plotly documentation example for lines on maps 绘制线条,但是在尝试单独为线条着色或设置样式时失败了。
理想情况下,我想使用 GeoJson/GeoPandas 文件中的颜色来添加颜色,但我只是没有到达那里。这是我所拥有的:
# https://github.com/telegeography/www.submarinecablemap.com
resp = session.get('https://raw.githubusercontent.com/telegeography/www.submarinecablemap.com/master/public/api/v2/cable/cable-geo.json')
gdf_sub_cables = gpd.read_file(resp.text)
gdf_sub_cables['color_hex'] = [f'#{x}' for x in gdf_sub_cables['color']]
lats = []
lons = []
names = []
colors = []
for feature,name,color in zip(gdf_sub_cables.geometry,gdf_sub_cables.slug,gdf_sub_cables.color_hex):
if isinstance(feature,shapely.geometry.linestring.Linestring):
linestrings = [feature]
elif isinstance(feature,shapely.geometry.multilinestring.MultiLinestring):
linestrings = feature.geoms
else:
continue
for linestring in linestrings:
x,y = linestring.xy
lats = np.append(lats,y)
lons = np.append(lons,x)
names = np.append(names,[name]*len(y))
colors = np.append(colors,[color]*len(y))
lats = np.append(lats,None)
lons = np.append(lons,None)
names = np.append(names,None)
colors = np.append(colors,None)
fig = px.line_geo(lat=lats,lon=lons,hover_name=names,projection="orthographic")
fig.show()
甚至绘制线条的方法似乎也过于复杂 - 如果有更好的绘制线条的方法,那就更好了。
感谢您的帮助!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)