【发布时间】:2021-06-25 00:53:55
【问题描述】:
我正在尝试将文本添加到下面的 plotly 地图中,原始代码修改自 https://plotly.com/python/lines-on-mapbox/
import plotly.graph_objects as go
fig = go.Figure(go.Scattermapbox(
mode = "markers",
marker = {'size': 10}))
fig.add_trace(go.Scattermapbox(
mode = "markers",
lon = longlist,
lat = latlist,
marker = {'size': 10}))
fig.update_layout(
margin ={'l':0,'t':0,'b':0,'r':0},
mapbox = {
'style': "stamen-terrain",
'center': {'lon': -20, 'lat': -20},
'zoom': 1})
fig.show()
我试图复制Plotly Scattermapbox: Is there a way to include some text above and below the markers?提供的解决方案
在下面查看我编辑的代码,其中包括从幅度列表中检索数据的新文本代码和 mapbox_access_token 的新代码
import plotly.graph_objects as go
mapbox_access_token = 'mytoken'
fig = go.Figure(go.Scattermapbox(
mode = "markers",
marker = {'size': 10}))
data = fig.add_trace(go.Scattermapbox(
mode = "markers",
lon = longlist,
lat = latlist,
marker = {'size': 10},
textposition='top right',
textfont=dict(size=16, color='black'),
text = magnitudelist
))
layout = dict(margin=dict(l=0, t=0, r=0, b=0, pad=0),
mapbox=dict(accesstoken=mapbox_access_token,
center=dict(lat=-20, lon=-20),
style='stamen-terrain',
zoom=1))
fig = go.Figure(data=data, layout=layout)
fig.show()
我正在尝试获得更像这样的结果
任何建议将不胜感激
【问题讨论】:
标签: plotly mapbox mapbox-marker