Skip to content

Conversation

@jonasvdd
Copy link
Member

@jonasvdd jonasvdd commented Jan 6, 2024

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
Copy link

codecov-commenter commented Jan 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

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

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

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonasvdd jonasvdd merged commit 46e629f into main Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants