简体   繁体   中英

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. 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. However when I set text=nodes.Node and hoverinfo="text" I see the list of all nodes when hovering over any point. Code below produces a minimal example (in 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
    ),
)

Am I setting text incorrectly? Or is it something to do with hoverinfo or hovermode ?

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]

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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