Skip to content

Commit 044ecd6

Browse files
committed
💨 add example
1 parent 1ef0296 commit 044ecd6

File tree

3 files changed

+404
-9
lines changed

3 files changed

+404
-9
lines changed

examples/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Additionally, this notebook also shows some more advanced functionalities, such
2323
* The flexibility of configuring different aggregation-algorithms and number of shown samples per trace
2424
* How plotly-resampler can be used for logarithmic x-axes and an implementation of a logarithmic aggregation algorithm, i.e., [LogLTTB](example_utils/loglttb.py)
2525
* Using different `fill_value` for gap handling of filled area plots.
26+
* Using multiple y-axes in a single subplot (see the [other_examples](other_examples.ipynb))
2627

2728
**Note**: the basic example notebook requires `plotly-resampler>=0.9.0rc3`.
2829

examples/other_examples.ipynb

+394
Large diffs are not rendered by default.

tests/test_multiple_axes.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from plotly.subplots import make_subplots
55

66
from plotly_resampler import FigureResampler, FigureWidgetResampler
7+
from plotly_resampler.aggregation import MinMaxLTTB
78

89

910
@pytest.mark.parametrize("fig_type", [FigureResampler, FigureWidgetResampler])
@@ -12,7 +13,9 @@ def test_multiple_axes_figure(fig_type):
1213
x = np.arange(200_000)
1314
sin = 3 + np.sin(x / 200) + np.random.randn(len(x)) / 30
1415

15-
fig = fig_type(default_n_shown_samples=2000)
16+
fig = fig_type(
17+
default_n_shown_samples=2000, default_downsampler=MinMaxLTTB(parallel=True)
18+
)
1619

1720
# all traces will be plotted against the same x-axis
1821
# note: the first added trace its yaxis will be used as reference
@@ -31,7 +34,6 @@ def test_multiple_axes_figure(fig_type):
3134
hf_y=(sin - 3) ** 2,
3235
)
3336

34-
# Create axis objects
3537
# in order for autoshift to work, you need to set x-anchor to free
3638
fig.update_layout(
3739
# NOTE: you can use the domain key to set the x-axis range (if you want to display)
@@ -40,7 +42,7 @@ def test_multiple_axes_figure(fig_type):
4042
# Add a title to the y-axis
4143
yaxis=dict(title="orig"),
4244
# by setting anchor=free, overlaying, and autoshift, the axis will be placed
43-
# autmoatically, without overlapping any other axes
45+
# automatically, without overlapping any other axes
4446
yaxis2=dict(
4547
title="negative",
4648
anchor="free",
@@ -92,7 +94,7 @@ def test_multiple_axes_subplot_rows(fig_type):
9294

9395
# create a figure with 2 rows and 1 column
9496
# NOTE: instead of the above methods, we don't add the "yaxis" argument to the
95-
# scatter object
97+
# scatter object
9698
fig = fig_type(make_subplots(rows=2, cols=1, shared_xaxes=True))
9799
fig.add_trace(go.Scatter(name="orig"), hf_x=x, hf_y=sin, row=2, col=1)
98100
fig.add_trace(go.Scatter(name="-orig"), hf_x=x, hf_y=-sin, row=2, col=1)
@@ -106,7 +108,6 @@ def test_multiple_axes_subplot_rows(fig_type):
106108
# add the original signal to the first row subplot
107109
fig.add_trace(go.Scatter(name="<b>orig</b>"), row=1, col=1, hf_x=x, hf_y=sin)
108110

109-
# Create axis objects
110111
# in order for autoshift to work, you need to set x-anchor to free
111112
fig.update_layout(
112113
xaxis2=dict(domain=[0, 1], anchor="y2"),
@@ -171,15 +172,14 @@ def test_multiple_axes_subplot_cols(fig_type):
171172
fig.add_trace(go.Scatter(name="-orig"), hf_x=x, hf_y=-sin, row=1, col=2)
172173
fig.add_trace(go.Scatter(name="sqrt"), hf_x=x, hf_y=np.sqrt(sin * 10), row=1, col=2)
173174
fig.add_trace(go.Scatter(name="orig**2"), hf_x=x, hf_y=(sin - 3) ** 2, row=1, col=2)
174-
#
175-
# NOTE: because of the row and col specification, the yaxis is automatically set to y2
175+
176+
# NOTE: because of the row & col specification, the yaxis is automatically set to y2
176177
for i, data in enumerate(fig.data[1:], 3):
177178
data.update(yaxis=f"y{i}")
178179

179180
fig.add_trace(go.Scatter(name="<b>orig</b>"), row=1, col=1, hf_x=x, hf_y=sin)
180181

181-
# Create axis objects
182-
# in order for autoshift to work, you need to set x-anchor to free
182+
# In order for autoshift to work, you need to set x-anchor to free
183183
fig.update_layout(
184184
xaxis=dict(domain=[0, 0.4]),
185185
xaxis2=dict(domain=[0.56, 1]),

0 commit comments

Comments
 (0)