Plotly Scattermapbox: Is there a way to include some text above and below the markers?(Plotly Scattermapbox:有没有办法在标记上方和下方包含一些文本?)
问题描述
In Plotly, using Scattermapbox, is there a way to display some text above and below the markers?
Currently the text only appears when I hover on the markers, and the plot shows only part of the text that I would like to display.
My input data frame df_area
is as follows. I would like to display the text contained in both the name
column and in the forecast
column.
name latitude longitude forecast
0 "AK" 2.675000 203.139000 "Cloudy"
1 "Bd" 2.621000 203.224000 "Cloudy"
However, I can currently only display the text in the forecast
column.
fig = go.Figure(go.Scattermapbox(
lat=df_area["latitude"],
lon=df_area["longitude"],
mode="markers+text",
marker={"size": 10},
text=df_area["forecast"]))
I included an example below, note that this requires a (free) mapbox access token.
import plotly.graph_objects as go
import pandas as pd
mapbox_access_token = 'your-free-token'
df = pd.DataFrame({'name': ['London', 'Oxford'],
'latitude': [51.509865, 51.7520],
'longitude': [-0.118092, -1.2577],
'forecast': ['Cloudy', 'Sunny']})
data = go.Scattermapbox(lat=list(df['latitude']),
lon=list(df['longitude']),
mode='markers+text',
marker=dict(size=20, color='green'),
textposition='top right',
textfont=dict(size=16, color='black'),
text=[df['name'][i] + '<br>' + df['forecast'][i] for i in range(df.shape[0])])
layout = dict(margin=dict(l=0, t=0, r=0, b=0, pad=0),
mapbox=dict(accesstoken=mapbox_access_token,
center=dict(lat=51.6, lon=-0.2),
style='light',
zoom=8))
fig = go.Figure(data=data, layout=layout)
这篇关于Plotly Scattermapbox:有没有办法在标记上方和下方包含一些文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Plotly Scattermapbox:有没有办法在标记上方和下方包含一些文本?
基础教程推荐
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01