go.Scatter and Markers Not Hovering

When I plot markers, I cannot get hover to work at all. It plots like it should, but it does not hover at all.

I am applying the same process I would use for mode = 'lines', which works like it should, meaning hover is functional.

Below is a MWE:

import pandas as pd
import plotly
import plotly.graph_objs as go

df = pd.DataFrame(columns=['x', 'y', 'text'])

df['x'] = [32.1, 32.3, 32.5, 32.7]
df['y'] = [61.3, 61.5, 61.7, 61.9]
df['text'] = ['Country A', 'Country B', 'Country C', 'Country D']

container = []
for x, plot in df.groupby('text'):
    trace = (go.Scatter(x=plot.x, y=plot.y, mode = 'markers',
                        name = x, hoverinfo ='text', marker = dict(size = 10)))
    container.append(trace)

fig = dict(data=container)
plotly.offline.plot(fig, validate=False) # offline plotting

I would appreciate any insight.

@localh85, in the traces above hoverinfo='text' but the text attribute isnโ€™t set so it gets the default value of "". If you set hoverinfo="name" youโ€™ll get the behaviour youโ€™re expecting.

1 Like

Perfect! Thank you very much it @michaelbabyn

Edit; Translating this to my actual data. It works, but hover is now limiting the amount of text shown. Any ideas?

truncated%20text

Huh, @localh85. I guess Plotly limits the length of the name attribute shown in hover text. Setting text=x in your trace and then switching hoverinfo='text' again should do the trick.

1 Like

Yep, that did the trick!

For future reference, you can also directly control the display width of the hover label using the scatter.hoverlabel.namelength property.

-Jon

1 Like