Reputation: 16079
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
?
Upvotes: 3
Views: 1508
Reputation: 31659
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]
Upvotes: 4