predict-idlab / plotly-resampler

Visualize large time series data with plotly.py
https://predict-idlab.github.io/plotly-resampler/latest
MIT License
1k stars 67 forks source link

[BUG] `FigureWidgetResampler`, `pandas` time-index series. #231

Closed jonasvdd closed 1 year ago

jonasvdd commented 1 year ago

There is a bug with the x-axis view when passing a non pd.(datetime)Index (i.e, a pd.Series) as hf_x (and likely x -> to test). An int-view of the x is shown as x-axis.

Related: #208

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

# Generate data
count = 1_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])

# Creat the figure
fig = FigureWidgetResampler(go.Figure())
# Setting the `hf_x` data via a `pd.Index` works
# fig.add_trace(go.Scatter(mode="lines"), hf_x=pd.Index(df["dt"]), hf_y=df["value"])
# Setting the `hf_x` data via a `pd.Series` creates an x-axis int0view
fig.add_trace(go.Scatter(mode="lines"), hf_x=df["dt"], hf_y=df["value"])
fig

Adding the trace its hf_x data via a pd.Series seems to create an int view (see 📷 1) whereas adding the hf_x via a pd.Index produces a data-x-axis (see 📷 2)

TODO:

jonasvdd commented 1 year ago

image

It appears adjusting this line in figure_resampler_interface class fixes this bug. Noteworthy, this bug only seams to appear for non tz-localized series.