Skip to content

Commit 525e029

Browse files
committed
🖊️ review code
1 parent 875abab commit 525e029

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

README.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
[![support-version](https://img.shields.io/pypi/pyversions/plotly-resampler)](https://img.shields.io/pypi/pyversions/plotly-resampler)
99
[![codecov](https://img.shields.io/codecov/c/github/predict-idlab/plotly-resampler?logo=codecov)](https://codecov.io/gh/predict-idlab/plotly-resampler)
1010
[![Code quality](https://img.shields.io/lgtm/grade/python/github/predict-idlab/plotly-resampler?label=code%20quality&logo=lgtm)](https://lgtm.com/projects/g/predict-idlab/plotly-resampler/context:python)
11+
[![Downloads](https://pepy.tech/badge/plotly-resampler)](https://pepy.tech/project/plotly-resampler)
1112
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?)](http://makeapullrequest.com)
1213
[![Documentation](https://github.com/predict-idlab/plotly-resampler/actions/workflows/deploy-docs.yml/badge.svg)](https://github.com/predict-idlab/plotly-resampler/actions/workflows/deploy-docs.yml)
1314
[![Testing](https://github.com/predict-idlab/plotly-resampler/actions/workflows/test.yml/badge.svg)](https://github.com/predict-idlab/plotly-resampler/actions/workflows/test.yml)
@@ -17,7 +18,7 @@
1718

1819
> `plotly_resampler`: visualize large sequential data by **adding resampling functionality to Plotly figures**
1920
20-
[Plotly](https://github.com/plotly/plotly.py) is an awesome interactive visualization library, however it can get pretty slow when a lot of data points are visualized (100 000+ datapoints). This library solves this by downsampling (aggregating) the data respective to the view and then plotting the aggregated points. When you interact with the plot (panning, zooming, ...), callbacks are used to aggregate and update the figure.
21+
[Plotly](https://github.com/plotly/plotly.py) is an awesome interactive visualization library, however it can get pretty slow when a lot of data points are visualized (100 000+ datapoints). This library solves this by downsampling (aggregating) the data respective to the view and then plotting the aggregated points. When you interact with the plot (panning, zooming, ...), callbacks are used to aggregate data and update the figure.
2122

2223
<p align="center">
2324
<a href="#readme">
@@ -54,11 +55,11 @@ To **add dynamic resampling** to your plotly Figure
5455
2. output the `FigureWidgetResampler` instance in a cell
5556

5657
> **Note**:
57-
> Any plotly Figure can be wrapped with FigureResampler and FigureWidgetResampler! 🎉
58+
> Any plotly Figure can be wrapped with `FigureResampler` and `FigureWidgetResampler`! 🎉
5859
> But, (obviously) only the scatter traces will be resampled.
5960
6061
> **Tip** 💡:
61-
> For significant faster initial loading of the Figure, we advise to wrap the constructor of the plotly Figure with `FigureResampler` and add the trace data as `hf_x` and `hf_y`
62+
> For significant faster initial loading of the Figure, we advise to wrap the constructor of the plotly Figure and add the trace data as `hf_x` and `hf_y`
6263
6364
### Minimal example
6465

@@ -69,7 +70,7 @@ from plotly_resampler import FigureResampler, FigureWidgetResampler
6970
x = np.arange(1_000_000)
7071
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000
7172

72-
# FigureResampler: dynamic aggregation via a Dash web-app
73+
# OPTION 1 - FigureResampler: dynamic aggregation via a Dash web-app
7374
fig = FigureResampler(go.Figure())
7475
fig.add_trace(go.Scattergl(name='noisy sine', showlegend=True), hf_x=x, hf_y=noisy_sin)
7576

@@ -79,7 +80,7 @@ fig.show_dash(mode='inline')
7980
#### FigureWidgetResampler: dynamic aggregation via `FigureWidget.layout.on_change`
8081
```python
8182
...
82-
# FigureWidgetResampler: dynamic aggregation via `FigureWidget.layout.on_change`
83+
# OPTION 2 - FigureWidgetResampler: dynamic aggregation via `FigureWidget.layout.on_change`
8384
fig = FigureWidgetResampler(go.Figure())
8485
fig.add_trace(go.Scattergl(name='noisy sine', showlegend=True), hf_x=x, hf_y=noisy_sin)
8586

@@ -89,7 +90,9 @@ fig
8990
### Features
9091

9192
* **Convenient** to use:
92-
* just add the `FigureResampler` decorator around a plotly Figure and call `.show_dash()`
93+
* just add either
94+
* `FigureResampler` decorator around a plotly Figure and call `.show_dash()`
95+
* `FigureWidgetResampler` decorator around a plotly Figure and output the instance in a cell
9396
* allows all other plotly figure construction flexibility to be used!
9497
* **Environment-independent**
9598
* can be used in Jupyter, vscode-notebooks, Pycharm-notebooks, Google Colab, and even as application (on a server)
@@ -100,9 +103,10 @@ fig
100103
### Important considerations & tips
101104

102105
* When running the code on a server, you should forward the port of the `FigureResampler.show_dash()` method to your local machine.<br>
103-
**note** that you can add dynamic aggregation to plotly figures with the `FigureWidgetResampler` wrapper.
106+
**Note** that you can add dynamic aggregation to plotly figures with the `FigureWidgetResampler` wrapper without needing to forward a port!
104107
* In general, when using downsampling one should be aware of (possible) [aliasing](https://en.wikipedia.org/wiki/Aliasing) effects.
105108
The <b><a style="color:orange">[R]</a></b> in the legend indicates when the corresponding trace is being resampled (and thus possibly distorted) or not. Additionally, the `~<range>` suffix represent the mean aggregation bin size in terms of the sequence index.
109+
106110
## Future work 🔨
107111

108112
* Support `.add_traces()` (currently only `.add_trace` is supported)

docs/sphinx/getting_started.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Getting started 🚀
77
``plotly-resampler`` serves two main **modules**:
88

99
* :py:mod:`figure_resampler <plotly_resampler.figure_resampler>`: a wrapper for *plotly.graph\_objects Figures*, coupling the dynamic resampling functionality to the *Figure*.
10-
* :py:mod:`aggregation <plotly_resampler.aggregation>`: a module withholds various data aggregation methods.
10+
* :py:mod:`aggregation <plotly_resampler.aggregation>`: a module that withholds various data aggregation methods.
1111

1212
Installation ⚙️
1313
---------------
@@ -42,11 +42,11 @@ Dynamic resampling callbacks are realized with either:
4242

4343
To **add dynamic resampling** using a **FigureWidget**, you should:
4444
1. wrap your plotly Figure (can be a ``go.Figure``) with :class:`FigureWidgetResampler <plotly_resampler.figure_resampler.FigureWidgetResampler>`
45-
2. Create a cell output for the ``FigureWidgetResampler`` instance
45+
2. output the ```FigureWidgetResampler`` instance in a cell
4646

4747
.. tip::
4848

49-
For **significant faster initial loading** of the Figure, we advise to wrap the constructor of the plotly Figure with :class:`FigureResampler <plotly_resampler.figure_resampler.FigureResampler>` and add the trace data as ``hf_x`` and ``hf_y``
49+
For **significant faster initial loading** of the Figure, we advise to wrap the constructor of the plotly Figure with either :class:`FigureResampler <plotly_resampler.figure_resampler.FigureResampler>` or :class:`FigureWidgetResampler <plotly_resampler.figure_resampler.FigureWidgetResampler>` and add the trace data as ``hf_x`` and ``hf_y``
5050

5151
.. note::
5252

plotly_resampler/figure_resampler/figure_resampler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(
5050
verbose,
5151
)
5252

53-
# The figureAggregator needs a dash app
53+
# The FigureResampler needs a dash app
5454
self._app: JupyterDash | Dash | None = None
5555
self._port: int | None = None
5656
self._host: str | None = None
@@ -96,7 +96,7 @@ def show_dash(
9696
graph_properties = {} if graph_properties is None else graph_properties
9797
assert "config" not in graph_properties.keys() # There is a param for config
9898
# 1. Construct the Dash app layout
99-
app = JupyterDash("local_app") # TODO -> was jupyterdash
99+
app = JupyterDash("local_app")
100100
app.layout = dash.html.Div(
101101
[
102102
dash.dcc.Graph(

plotly_resampler/figure_resampler/figure_resampler_interface.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131

3232
class AbstractFigureAggregator(BaseFigure, ABC):
33+
"""Abstract interface for data aggregation functionality for plotly figures."""
34+
3335
def __init__(
3436
self,
3537
figure: BaseFigure,

plotly_resampler/figure_resampler/figurewidget_resampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FigureWidgetResampler(
4040

4141
def __init__(
4242
self,
43-
figure: go.FigureWidget,
43+
figure: go.FigureWidget | go.Figure = go.Figure(),
4444
convert_existing_traces: bool = True,
4545
default_n_shown_samples: int = 1000,
4646
default_downsampler: AbstractSeriesAggregator = EfficientLTTB(),

0 commit comments

Comments
 (0)