为 Plotly 地图中的单条线 GeoJson/GeoPandas 线段着色

问题描述

我正在使用 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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...