使用Plotly Scattermapbox轨迹在地图上添加标记NAME



我需要支持使用Plotly Scattermapbox痕迹在地图上添加标记NAME。

下面的代码显示了标记和线条,我想在地图上显示标记的名称:

import plotly.graph_objects as go
fig = go.Figure(go.Scattermapbox(
mode = "markers+lines",
lon = [10, 20, 30],
lat = [10, 20,30],
marker = {'size': 10}))
fig.add_trace(go.Scattermapbox(
mode = "markers+lines",
lon = [-50, -60,40],
lat = [30, 10, -20],
marker = {'size': 10}))
fig.update_layout(
margin ={'l':0,'t':0,'b':0,'r':0},
mapbox = {
'center': {'lon': 10, 'lat': 10},
'style': "stamen-terrain",
'center': {'lon': -20, 'lat': -20},
'zoom': 1})
fig.show()

您可以使用mode = "markers+text+lines"并提供文本字段

mode -确定此散射轨迹的绘制模式。如果如果模式包含" text ",则文本元素将出现在坐标。否则,文本元素将出现在悬停位置。

fig = go.Figure(go.Scattermapbox(
mode = "markers+text+lines",
lon = [10, 20, 30],
lat = [10, 20,30],
marker = {'size': 10},
text = ["name1", "name2", "name3"], 
textposition = "bottom right")
)

有一个已知的错误会阻止非mapbox样式显示文本

https://github.com/plotly/plotly.js/issues/4110

登录mapbox并创建一个新的自定义,解决了一些人的这个问题:

https://community.plotly.com/t/scattermapbox-doesnt-work-with-marker-mode-as-text/35065/4