plotly-resampler icon indicating copy to clipboard operation
plotly-resampler copied to clipboard

Feat/candlesticks

Open jonasvdd opened this issue 1 year ago • 2 comments

related: #288, #98

TODO:

  • [ ] do we need to lock tsdownsample version (as we now have a hard lock-in on tsdownsample's m4 implementation)?
  • [ ] maybe allow the users to configure the candlestick position? (middle of bucket, begin (as it is now), or end)
  • [ ] write docs (and focus on limitations)
  • [ ] create examples
  • [ ] write tests (few datapoints, large zoom-in); how does it behave with different aggregators?

Minimal example:

import pandas as pd; import numpy as np
import plotly.graph_objects as go
from plotly_resampler import FigureResampler
from plotly_resampler.aggregation import M4


# 1. Create dummy data
x = np.arange(2_000_000)
x_time = pd.date_range("2020-01-01", periods=len(x), freq="1min")
noisy_sin = (3 + np.sin(x / (len(x) / 55)) + np.random.randn(len(x)) / 10) * x / 1_000

# 2. Create a figure
fig = FigureResampler(default_n_shown_samples=1000, verbose=False)
fig.add_trace(
    go.Scattergl(name="Original", mode="lines", visible="legendonly"),
    hf_x=x_time,
    hf_y=noisy_sin,
)
fig.add_trace(
    go.Candlestick(name="OHLC"),
    hf_x=x_time,
    hf_y=noisy_sin,
    downsampler=M4(parallel=True),
    max_n_samples=400,
)
fig.update_layout(title="OHLC Downsampling", showlegend=True)
fig.update_xaxes(rangeslider_visible=False)
fig

Peek 2024-01-13 19-58

jonasvdd avatar Jan 13 '24 18:01 jonasvdd

Codecov Report

Attention: 33 lines in your changes are missing coverage. Please review.

Comparison is base (46e629f) 96.42% compared to head (5cdb8f4) 93.75%. Report is 2 commits behind head on main.

Files Patch % Lines
...ler/figure_resampler/figure_resampler_interface.py 21.05% 30 Missing :warning:
plotly_resampler/aggregation/aggregators.py 50.00% 3 Missing :warning:

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #289      +/-   ##
==========================================
- Coverage   96.42%   93.75%   -2.67%     
==========================================
  Files          14       14              
  Lines        1146     1185      +39     
==========================================
+ Hits         1105     1111       +6     
- Misses         41       74      +33     

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

codecov-commenter avatar Jan 13 '24 19:01 codecov-commenter

@jvdd, I suppose we should rebase this branch on main? (so we can fix the NanM4 issue in this PR as well?

jonasvdd avatar Mar 12 '24 13:03 jonasvdd