Skip to content

Commit 59c70ab

Browse files
authored
Update README.md
1 parent 392f8aa commit 59c70ab

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

README.md

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,54 @@ In [this Plotly-Resampler demo](https://github.com/predict-idlab/plotly-resample
4747
## Usage
4848

4949
To **add dynamic resampling** to your plotly Figure
50-
* using a web application with *Dash* callbacks, you should;
51-
1. wrap the plotly Figure with `FigureResampler`
52-
2. call `.show_dash()` on the Figure
53-
* within a *jupyter* environment and *without creating a web application*, you should:
50+
<details>
51+
<summary>within a <b><i>jupyter</i> environment without creating a <i>web application</i></b></summary>
52+
<br>
53+
5454
1. wrap the plotly Figure with `FigureWidgetResampler`
5555
2. output the `FigureWidgetResampler` instance in a cell
56+
57+
**example code**:
58+
```python
59+
import plotly.graph_objects as go; import numpy as np
60+
from plotly_resampler import FigureResampler, FigureWidgetResampler
61+
62+
x = np.arange(1_000_000)
63+
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000
64+
65+
# OPTION 1 - FigureWidgetResampler: dynamic aggregation via `FigureWidget.layout.on_change`
66+
fig = FigureWidgetResampler(go.Figure())
67+
fig.add_trace(go.Scattergl(name='noisy sine', showlegend=True), hf_x=x, hf_y=noisy_sin)
68+
69+
fig
70+
```
71+
72+
</details>
73+
<details>
74+
<summary>using a <b><i>web-application</i> with <a href="https://github.com/plotly/dash">dash</a></b> callbacks</summary>
75+
<br>
76+
77+
1. wrap the plotly Figure with `FigureResampler`
78+
2. call `.show_dash()` on the `Figure`
79+
80+
**example code**:
81+
```python
82+
import plotly.graph_objects as go; import numpy as np
83+
from plotly_resampler import FigureResampler, FigureWidgetResampler
84+
85+
x = np.arange(1_000_000)
86+
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000
87+
88+
# OPTION 2 - FigureResampler: dynamic aggregation via a Dash web-app
89+
fig = FigureResampler(go.Figure())
90+
fig.add_trace(go.Scattergl(name='noisy sine', showlegend=True), hf_x=x, hf_y=noisy_sin)
91+
92+
fig.show_dash(mode='inline')
93+
```
94+
95+
</details>
96+
97+
---
5698

5799
> **Note**:
58100
> Any plotly Figure can be wrapped with `FigureResampler` and `FigureWidgetResampler`! 🎉
@@ -61,31 +103,6 @@ To **add dynamic resampling** to your plotly Figure
61103
> **Tip** 💡:
62104
> 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`
63105
64-
### Minimal example
65-
66-
```python
67-
import plotly.graph_objects as go; import numpy as np
68-
from plotly_resampler import FigureResampler, FigureWidgetResampler
69-
70-
x = np.arange(1_000_000)
71-
noisy_sin = (3 + np.sin(x / 200) + np.random.randn(len(x)) / 10) * x / 1_000
72-
73-
# OPTION 1 - FigureResampler: dynamic aggregation via a Dash web-app
74-
fig = FigureResampler(go.Figure())
75-
fig.add_trace(go.Scattergl(name='noisy sine', showlegend=True), hf_x=x, hf_y=noisy_sin)
76-
77-
fig.show_dash(mode='inline')
78-
```
79-
80-
#### FigureWidgetResampler: dynamic aggregation via `FigureWidget.layout.on_change`
81-
```python
82-
...
83-
# OPTION 2 - FigureWidgetResampler: dynamic aggregation via `FigureWidget.layout.on_change`
84-
fig = FigureWidgetResampler(go.Figure())
85-
fig.add_trace(go.Scattergl(name='noisy sine', showlegend=True), hf_x=x, hf_y=noisy_sin)
86-
87-
fig
88-
```
89106

90107
### Features
91108

@@ -111,7 +128,7 @@ fig
111128

112129
## Future work 🔨
113130

114-
* Support `.add_traces()` (currently only `.add_trace` is supported)
131+
- [x] Support `.add_traces()` (currently only `.add_trace` is supported)
115132

116133
<br>
117134

0 commit comments

Comments
 (0)