Skip to content

Figure with multiple matching go.Scattergl traces have wrong hover order #4018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lamhoangtung opened this issue Jan 16, 2023 · 2 comments
Closed

Comments

@lamhoangtung
Copy link

lamhoangtung commented Jan 16, 2023

Hi. I discover that figure with multiple matching go.Scattergl traces have wrong hover order. Consider this example:

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scattergl(
    x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], y=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    line_color='rgb(0,100,80)',
    name='Normal',
))

fig.add_trace(go.Scattergl(
    x=[5, 6], y=[5, 6],
    mode='markers',
    marker_color='rgb(255,0,0)',
    name='Abnormal',
))

fig.show()

I get this plot:
image
When I hover on the [5,5] points, the hover text should be in Red and say "Abnormal", but its not.

If I flip the trace order like this:

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scattergl(
    x=[5, 6], y=[5, 6],
    mode='markers',
    marker_color='rgb(255,0,0)',
    name='Abnormal',
))

fig.add_trace(go.Scattergl(
    x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], y=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    line_color='rgb(0,100,80)',
    name='Normal',
))

fig.show()

I get this plot:
image
Which have the correct hover text, but all the red markers are behind the green markers.

This does not happen for normal go.Scatter trace:

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter(
    x=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], y=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    line_color='rgb(0,100,80)',
    name='Normal',
))

fig.add_trace(go.Scatter(
    x=[5, 6], y=[5, 6],
    mode='markers',
    marker_color='rgb(255,0,0)',
    name='Abnormal',
))

fig.show()

image

So clearly this is a bug. Can someone take a look and fix this ?

Thanks for checking by!

@AaronStiff
Copy link
Contributor

Duplicate of #2079

@AaronStiff
Copy link
Contributor

A few options for workarounds:

Display both Normal and Abnormal points together:

fig.update_layout(hovermode = "x unified")

Display none of the Normal points, but display the Abnormal points

fig.update_traces(hoverinfo="skip",selector={"name":"Normal"})

@AaronStiff AaronStiff marked this as a duplicate of #2079 Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants