我无法让 plotly 的 hoverinfo
属性显示给定点的单个值。作为引用,我在 map 上绘制了一堆点,并希望能够将鼠标悬停在一个点上并查看其唯一标识符。如果我没有为 hoverinfo
或 text
设置任何值,我会在悬停时看到单个点的纬度和经度值。但是,当我设置 text=nodes.Node
和 hoverinfo="text"
时,将鼠标悬停在任意点上时,我会看到所有节点的列表。下面的代码产生了一个最小的例子(在 jupyter notebook 中):
import pandas as pd
import plotly.offline as py
from plotly.graph_objs import *
py.init_notebook_mode()
nodes = pd.DataFrame({
'Node': [103,131,136,143,153],
'Lat': [39.97703048,39.98315706,40.02686848,40.02110808,40.01174032],
'Lon': [-83.00179533,-82.97803884,-82.97319305,-83.01509991,-82.97285888]
})
mapbox_access_token = some_mapbox_token
data = Data([
Scattermapbox(
lat=nodes.Lat,
lon=nodes.Lon,
mode='markers',
marker=Marker(
size=2,
color='red',
opacity=0.7
),
text=nodes.Node,
hoverinfo='text'
)]
)
layout = Layout(
title='Nodes interacting with busiest TAZ',
autosize=True,
hovermode='Closest',
showlegend=False,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
center=dict(
lat=39.983333,
lon=-82.983333
),
pitch=0,
zoom=7.5
),
)
我是否错误地设置了 text
?还是与 hoverinfo
或 hovermode
有关?
最佳答案
关于python - Plotly hoverinfo 显示所有数据点而不是当前点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42723442/