简体   繁体   English

Plotly hoverinfo显示所有数据点而不是当前点

[英]Plotly hoverinfo shows all data points instead of current point

I am having trouble getting plotly's hoverinfo attribute to display a single value for a given point. 我无法获得plotly的hoverinfo属性来显示给定点的单个值。 For reference I am plotting a bunch of points on a map and would like to be able to hover over a point and see its unique identifier. 作为参考,我在地图上绘制了一堆点,并希望能够将鼠标悬停在一个点上并查看其唯一标识符。 If I don't set any value for hoverinfo or text I see the lat and lon values for an individual point when hovering. 如果我没有为hoverinfotext设置任何值,我会在悬停时看到单个点的lat和lon值。 However when I set text=nodes.Node and hoverinfo="text" I see the list of all nodes when hovering over any point. 但是,当我设置text=nodes.Nodehoverinfo="text"我会在悬停在任何点上时看到所有节点的列表。 Code below produces a minimal example (in jupyter notebook): 下面的代码生成一个最小的例子(在jupyter笔记本中):

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
    ),
)

Am I setting text incorrectly? 我的text设置不正确吗? Or is it something to do with hoverinfo or hovermode ? 或者它与hoverinfohovermode

Looks like a bug or unspecified behavior to me. 看起来像是一个错误或未指定的行为给我。 Your code looks perfectly fine, you would just need to pass a list of strings instead of integers and it should work. 你的代码看起来很好,你只需要传递一个字符串列表而不是整数,它应该工作。

    text=[str(n) for n in nodes.Node]

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM