[Python] Issue with plotly.resampler

Discussão em 'Python' iniciado por Stack, Julho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I am getting unexpected behavior from running plotly resampler. In jupyter notebook, I have the following code. There are 5000 samples and I set the samples to plot before resampling to 1000 for default and both traces. So I should expect to see resampling when I'm zoomed out (5000 points plotted, >1000 so resample) but I should see all raw data when I zoom up close (~10 points plotted, <1000 so don't resample). However, no matter how closely I zoom I see that the data is being is resampled (legend shows R, indicating resampling).

    In particular, the red 0 trace is being resampled and because of limitations of resampler used, the x-axis for 0 data is corrupted (see zoomed in plot, where two first points are bunched up).

    Zoomed out fully (expect resampling, legend indicates resampling, so good

    Zoomed in fully (expect no resampling, legend indicates resampling, so bad

    from plotly_resampler import FigureWidgetResampler

    import pandas as pd
    import numpy as np

    x = pd.date_range("2023-01-01", periods=5000, freq="ms")
    y = np.sin(np.linspace(0, 10 * np.pi, 5000)) * 0 + np.arange(5000)
    z = np.sin(np.linspace(0, 10 * np.pi, 5000)) * 0

    fig = FigureWidgetResampler(default_n_shown_samples=1000)

    fig.add_trace(
    {"name": "Signal Linear", "x": x, "y": y, "mode": 'lines+markers'},
    max_n_samples=1000,
    limit_to_view=True
    )

    fig.add_trace(
    {"name": "Signal 0", "x": x, "y": z, "mode": 'lines+markers'},
    max_n_samples=1000,
    limit_to_view=True
    )

    fig.update_layout(showlegend=True)

    fig.show()


    Versions: plotly: 5.24.1 plotly-resampler: 0.10.0 Running code from jupyter notebook on windows

    Continue reading...

Compartilhe esta Página