predict-idlab / plotly-resampler

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

:sparkles: fix for #275 #286

Closed jonasvdd closed 9 months ago

jonasvdd commented 9 months ago

Working example (clone this branch, run the code below in a notebook)

data: data.csv code:

from plotly_resampler import register_plotly_resampler
import plotly.graph_objects as go

import pandas as pd

# NOTE: via the create_overview=True argument, we can create an rangeslider
register_plotly_resampler(mode="figure", create_overview=True, verbose=True)

df_hourly = pd.read_csv("data.csv", index_col=0)
hourly_fig = go.Figure()
hourly_fig.add_trace(
    go.Scatter(
        x=df_hourly["Date"],
        y=df_hourly["MWh"],
        name="Hourly position",
        mode="lines",
        showlegend=True,
    )
)
hourly_fig.update_layout(
    dragmode="pan",
    hovermode="x unified",
    # fmt: off
    # NOTE: call this after adding all traces
    # yaxis=dict(autorange=False),
    xaxis=dict(rangeselector=dict(buttons=list([
        dict(count=1, label="1 day", step="day", stepmode="backward"),
        dict(count=1, label="1 month", step="month", stepmode="backward"),
        dict(count=1, label="1 year", step="year", stepmode="backward"),
    ]))),
    # fmt: on
    template="plotly_white",
    legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
)

hourly_fig.show_dash(mode="external")

output: ⬇️ rangeselector

codecov-commenter commented 9 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (2b79498) 96.42% compared to head (3d43a2d) 96.42%.

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #286 +/- ## ======================================= Coverage 96.42% 96.42% ======================================= Files 14 14 Lines 1146 1146 ======================================= Hits 1105 1105 Misses 41 41 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.