Exuperie
Exuperie

Reputation: 23

Plotly in python: hover display doesn't differentiate along x axis?

I'm new to plotly for python, and ran into a problem today: when I do scatter plots, hover display only works if the points have different x values. Please see the attached example.

I've tried formatting hoverinfo as "x+y", but it didn't make a difference. Is there a workaround for this, so I can display entries with different y values but same x value? Many thanks in advance for the help!

x=np.zeros(10)
y=np.arange(0,10,1)
trace1=go.Scatter(x=x, y=y)
data1=[trace1]
`enter code here`plotly.offline.iplot(data1)

only one hover label shows up: only one hover label shows up

Upvotes: 2

Views: 947

Answers (1)

Maximilian Peters
Maximilian Peters

Reputation: 31659

Try setting hovermode to closest in layout.

import plotly
plotly.offline.init_notebook_mode()

x = [0] * 10
y = [y for y in range(0, 10)]
data = [plotly.graph_objs.Scatter(x=x, y=y)]
layout = plotly.graph_objs.Layout(hovermode='closest')
figure = plotly.graph_objs.Figure(data=data, layout=layout)
plotly.offline.iplot(figure)

enter image description here

Upvotes: 3

Related Questions