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

[BUG] Hover data does not match the displayed resampled point in scatter plot #270

Closed
aasmune opened this issue Nov 8, 2023 · 1 comment Β· Fixed by #272
Closed

[BUG] Hover data does not match the displayed resampled point in scatter plot #270

aasmune opened this issue Nov 8, 2023 · 1 comment Β· Fixed by #272
Labels
bug Something isn't working

Comments

@aasmune
Copy link

aasmune commented Nov 8, 2023

Describe the bug πŸ–οΈ
When using register_plotly_resampler, hover data specified through hover_data argument to px.scatter sometimes shows up with incorrect values when hovering over a point with the mouse. The correct value is displayed when not using register_plotly_resampler.

Reproducing the bug πŸ”

import plotly.express as px
from plotly_resampler import register_plotly_resampler

import pandas as pd
import numpy as np

labels = list(range(0, 3))
np.random.seed(0xdeadbeef)
x = np.random.normal(size=100000)
y = np.random.normal(size=100000)
label = np.random.randint(low=labels[0], high=labels[-1]+1, size=100000).astype(str)
description = np.random.randint(low=3, high=5, size=100000)

df = pd.DataFrame.from_dict({"x": x, "y": y, "label": label, "description": description})

x_label = 'x'
y_label = 'y'
label_label = "label"
df = df.sort_values(by=[x_label])

print("Highlighted point on screenshot:")
print(df[np.isclose(df[x_label], 3.864907)])

# Without resampler, shows correct hover data
fig = px.scatter(df, x=x_label, y=y_label, color=label_label, title=f"Without resampler", hover_data=["description"])
fig.show()

# With resampler, shows incorrect hover data
register_plotly_resampler(mode="auto", default_n_shown_samples=10000)
fig2 = px.scatter(df, x=x_label, y=y_label, color=label_label, title=f"With resampler", hover_data=["description"])
fig2.show()

Printing the highlighted point in the screenshots:

Highlighted point on screenshot:
              x         y label  description
51820  3.864907  0.705485     0            3

Expected behavior πŸ”§
I expect the hover data to be correct for the displayed resampled point.

Screenshots πŸ“Έ
Without resampler - shows correct hover data
without_resampler

With resampler - shows incorrect hover data
with_resampler

Environment information:

  • OS: Ubuntu 20.04
  • Python environment:
    • Python version: 3.8.10
    • plotly-resampler environment: No virtual environments, installed though pip on host environment. Figures are displayed in Firefox.
  • plotly-resampler version: 0.9.1
  • plotly version: 5.18.0
  • pandas version: 2.0.3
  • numpy version: 1.24.4
@aasmune aasmune added the bug Something isn't working label Nov 8, 2023
@jonasvdd
Copy link
Member

jonasvdd commented Nov 9, 2023

Hi @aasmune,

Thank you for submitting this bug, I will look into this somewhere later this week and come back to you!

p.s: The aggregators that plotly-resampler employs are designed for selecting datapoints from consecutive/sequential/temporal data (which often boils down to selecting vertical extrema as can be seen in your resampled plot!). For x vs. y scatters, there may be other dimensionality reduction techniques that may be more suitable.

Kind regards,
Jonas

jonasvdd added a commit that referenced this issue Nov 10, 2023
jonasvdd added a commit that referenced this issue Nov 20, 2023
* :plane: fix for #270

* ✨ add `customdata` to hf_data_container

* πŸ’ͺ adding tests

* πŸ’¨ linting

* πŸ™ˆ fix futurewarning

* 🧹 formatting

* πŸ™ˆ fix tests

* ✈️ ➑️ πŸ‡§πŸ‡ͺ Autosize support (#273)

* ✈️ πŸ‡§πŸ‡ͺ fix for #259

* πŸ’¨ linting

* πŸ’¨ adding autosize support

* ✨ updating action versions

* πŸ™ˆ skip dtype test on window

* πŸ™ skip test

---------

Co-authored-by: Jeroen Van Der Donckt <boebievdd@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants