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: Resampling not working when using xaxis type='date' #181

Open
Jeremy38100 opened this issue Mar 31, 2023 · 2 comments
Open

Bug: Resampling not working when using xaxis type='date' #181

Jeremy38100 opened this issue Mar 31, 2023 · 2 comments
Assignees
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@Jeremy38100
Copy link

To improve performance I would like to use epoch timestamp in ms as x axis data, but show date in string format.
When I use the parameter type="date" it breaks the resampler I can no longer zoom in the chart

Code to reproduce :

import pandas as pd
import plotly.graph_objs as go
from plotly_resampler import FigureResampler
import random
import datetime

# Generate data
count = 100000
df = pd.DataFrame({
    'dt': pd.date_range(start='2021-01-01', periods=count, freq='S'),
})
df['value'] = df['dt'].apply(lambda x: random.randint(1, 100))
df['timestamp'] = (df['dt'] - datetime.datetime(1970, 1, 1)) // datetime.timedelta(milliseconds=1)

fig = FigureResampler(go.Figure())

fig.add_trace(go.Scatter(x = df['timestamp'], y = df['value'], mode = 'lines'))

fig.update_xaxes(type="date")
fig.show_dash(mode='inline')
@jvdd jvdd added the bug Something isn't working label Apr 3, 2023
@jvdd jvdd self-assigned this Apr 3, 2023
@jonasvdd jonasvdd self-assigned this Apr 5, 2023
@jvdd
Copy link
Member

jvdd commented Apr 24, 2023

Hey @Jeremy38100,

Thx for submitting this issue together with the reproducible code! 👍

I am able to reproduce this bug on my machine - I narrowed the underlying issue down to plotly-resampler internally using a stateful version of the xaxes type (but as you change this to type "date" - the internal value does not get changed & thus remains "linear" instead of "date")

I hope to solve this bug in the near future :)

@jonasvdd
Copy link
Member

Hi @Jeremy38100,

I looked into this, and for me it doesn't make 100% sense why you would convert your timestamp (and possible timezone aware array) into unix ms- epochs?

You mentioned that you had performance issues. Can these be tackled by adding your trace data not via the go.Scatter / go.Scattergl its x and y properties, but via the hf_x and hhf_y properties, as shown below?
This can be found aswell in the docs

Using 10M datapoints; and settign the data via hf_x and hf_y, I get the same type of visualization as above, and this runs <1s on a consumer pc.

import pandas as pd; import plotly.graph_objs as go; import numpy as np
from plotly_resampler import FigureResampler

# Generate data
count = 10_000_000
df = pd.DataFrame({"dt": pd.date_range(start="2021-01-01", periods=count, freq="S")})
df["value"] = np.random.randn(df.shape[0])

fig = FigureResampler(go.Figure())
fig.add_trace(go.Scatter(mode="lines"), hf_x=df["dt"], hf_y=df["value"])
fig

Please let me know if this helps you any further.
Kind regards,
Jonas

@jonasvdd jonasvdd added the wontfix This will not be worked on label May 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants