Skip to content
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

Scattergl freezes when y values have lots of zeros #6792

Open
karosc opened this issue Aug 5, 2021 · 2 comments
Open

Scattergl freezes when y values have lots of zeros #6792

karosc opened this issue Aug 5, 2021 · 2 comments
Labels
bug something broken P2 considered for next cycle performance something is slow sev-2 serious problem

Comments

@karosc
Copy link

karosc commented Aug 5, 2021

This might be more to do with plotly.js or plotly.py, but I only have dash code to generate the plot so I am posting here. I do a lot of time series plotting for my work, so Scattergl comes in handy because I routinely plot 1000's of points on a trace. After updating to dash 1.21.0, I noticed the Scattergl plots hang on hovering when my trace has lots of consecutive zero y-values. In most cases the hover event will freeze the entire page and I need to close and reopen the page.

EDIT: I pinpointed this error to the upgrade from plotly.js v2.0.0-rc.1 to plotly.js v2.0.0-rc.2. If you put rc.1 in the assets folder, scattergl works fast like in the previous version of dash. If you put rc.2 in the assets folder, the issues return.

I am not a js developer, so I don't know how best to move this issue over to plotly.js with equivalent js example. Nevertheless, I looked the difference in rc.1 and rc.2 changelogs and found that in rc.2 there is an additional reference to scattergl: Improve scattergl performance when using typed arrays #5632, maybe that is causing the issue?

Check the code below for an example:

import plotly.graph_objects as go
import numpy as np
import dash
import dash_core_components as dcc
import pandas as pd
import random

# build dataset
N = 200000
index = pd.date_range("7/1/2020", "7/1/2021", N)
vals = np.zeros(N)

# add some random non-zero data around the dataset
for i in range(50):
    start = random.randint(0, N - 50)
    vals[start : start + 50] = np.random.random(50)

# uncomment this line and see how Scattergl is much faster without the consecutive zeros
# vals = np.random.random(N)


# change Scattergl to Scatter to see how Scatter performs better with consecutive zeros
fig = go.Figure()
fig.add_trace(
    go.Scattergl(
        x=index,
        y=vals,
    )
)

app = dash.Dash()
app.layout = dcc.Graph(figure=fig)

if __name__ == "__main__":
    app.run_server(host="0.0.0.0", port=8080, debug=True)
@wkwg
Copy link

wkwg commented Nov 4, 2021

+1

Just ran into this issue today. I found out:

  1. This issue also applies to unbalanced datasets (lots of consecutive 1s and occasionally 0s or vice versa). Also it doesn't need to be 1 and 0s. It can be other values, as long as the dataset has a length of consecutive values.
  2. You can unfreeze the plot by disabling hovering (i.e., go.Scattergl(x=x, y=y, mode='markers', hoverinfo='skip'))

@wilecoyote2015
Copy link

This problem still persists for me.

@Coding-with-Adam Coding-with-Adam transferred this issue from plotly/dash Nov 22, 2023
@Coding-with-Adam Coding-with-Adam added bug something broken sev-2 serious problem labels Nov 22, 2023
@gvwilson gvwilson self-assigned this Jul 12, 2024
@gvwilson gvwilson removed their assignment Aug 2, 2024
@gvwilson gvwilson added P2 considered for next cycle performance something is slow labels Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P2 considered for next cycle performance something is slow sev-2 serious problem
Projects
None yet
Development

No branches or pull requests

5 participants