散点图散点图框,无法向标记添加文本 [英] Plotly Scattermapbox, unable to add text to markers
本文介绍了散点图散点图框,无法向标记添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试向下面的地图添加文本,原始代码是从我试图复制
我正在尝试获得更像这样的结果
任何建议将不胜感激
解决方案
我遇到了同样的问题,请尝试以下操作:
- 包括文本"在Scattermapbox模式下,并指定要显示的字符串或字符串数组:
fig.add_trace(go.Scattermapbox(模式=标记+文本",#包含文本模式lon = longlist,lat = latlist,marker = {'size':10},text = textlist)) # 包含文本列表
- 尝试使用另一种mapbox样式,例如"light":
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 ='light',#更改地图框样式zoom = 1))
I am trying to add text to the plotly map below, original code modified from 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()
I have tried to copy the solution provided at Plotly Scattermapbox: Is there a way to include some text above and below the markers?
See my edited code below which includes new text code to retrieve data from magnitudelist and new code for 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()
Result blank
I am trying to get a result more like this
Any suggestions would be appreciated
解决方案
I had the same problem, try the following:
- Include "text" in the Scattermapbox mode and specify a string or array of strings to show:
fig.add_trace(go.Scattermapbox(
mode = "markers+text", # include text mode
lon = longlist,
lat = latlist,
marker = {'size': 10},
text = textlist)) # include text list
- Try another mapbox style, like "light":
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='light', # change mapbox style
zoom=1))
这篇关于散点图散点图框,无法向标记添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文