From 01f6d845716635da7947ab63c238658ff09e2ffe Mon Sep 17 00:00:00 2001 From: Demetris Roumis Date: Mon, 15 Apr 2024 13:59:54 -0700 Subject: [PATCH 1/4] allow algo str input to downsample op --- hvplot/converter.py | 26 +++++++++++++++++++++++--- hvplot/tests/testoperations.py | 8 ++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/hvplot/converter.py b/hvplot/converter.py index 48683c148..c2997a382 100644 --- a/hvplot/converter.py +++ b/hvplot/converter.py @@ -206,9 +206,24 @@ class HoloViewsConverter: the Datashader library, returning an RGB object instead of individual points downsample (default=False): - Whether to apply LTTB (Largest Triangle Three Buckets) - downsampling to the element (note this is only well behaved for - timeseries data). Requires HoloViews >= 1.16. + Controls the application of downsampling to the plotted data, + which is particularly useful for large timeseries datasets to + reduce the amount of data sent to browser and improve + visualization performance. Requires HoloViews >= 1.16. Acceptable + values: - False: No downsampling is applied. - True: Applies + downsampling using HoloViews' default algorithm + (LTTB - Largest Triangle Three Buckets). + - 'lttb': Explicitly applies the Largest Triangle Three Buckets + algorithm. + - 'minmax': Applies the MinMax algorithm, selecting the minimum + and maximum values in each bin. + - 'm4': Applies the M4 algorithm, selecting the minimum, maximum, + first, and last values in each bin. + - 'minmax-lttb': Combines MinMax and LTTB algorithms for + downsampling, first applying MinMax to reduce to a preliminary + set of points, then LTTB for further reduction. + Other string values corresponding to supported algorithms in + HoloViews may also be used. dynspread (default=False): For plots generated with datashade=True or rasterize=True, automatically increase the point size when the data is sparse @@ -1321,6 +1336,11 @@ def method_wrapper(ds, x, y): except ImportError: raise ImportError('Downsampling requires HoloViews >=1.16') + # Let HoloViews choose the default algo if 'downsample' is True. + # Otherwise, user-specified algorithm + if isinstance(self.downsample, str): + opts['algorithm'] = self.downsample + if self.x_sampling: opts['x_sampling'] = self.x_sampling if self._plot_opts.get('xlim') is not None: diff --git a/hvplot/tests/testoperations.py b/hvplot/tests/testoperations.py index b3d5e4ef6..d946e26d3 100644 --- a/hvplot/tests/testoperations.py +++ b/hvplot/tests/testoperations.py @@ -319,3 +319,11 @@ def test_downsample_opts(self): assert plot.callback.operation.p.height == 50 assert plot.callback.operation.p.x_sampling == 5 assert plot.callback.operation.p.x_range == (0, 5) + + def test_downsample_algorithm_minmax(self): + from holoviews.operation.downsample import downsample1d + + plot = self.df.hvplot.line(downsample='minmax') + + assert isinstance(plot.callback.operation, downsample1d) + assert plot.callback.operation.algorithm == 'minmax' From 167f171f8bf508350085514403f7153cff8d828f Mon Sep 17 00:00:00 2001 From: Demetris Roumis Date: Mon, 15 Apr 2024 15:07:10 -0700 Subject: [PATCH 2/4] check the correct property in test --- hvplot/tests/testoperations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hvplot/tests/testoperations.py b/hvplot/tests/testoperations.py index d946e26d3..97f2ad384 100644 --- a/hvplot/tests/testoperations.py +++ b/hvplot/tests/testoperations.py @@ -326,4 +326,4 @@ def test_downsample_algorithm_minmax(self): plot = self.df.hvplot.line(downsample='minmax') assert isinstance(plot.callback.operation, downsample1d) - assert plot.callback.operation.algorithm == 'minmax' + assert plot.callback.operation_kwargs['algorithm'] == 'minmax' From a0233e04a2b7bd1db9ea8be492a79e7f8ab50424 Mon Sep 17 00:00:00 2001 From: Demetris Roumis Date: Mon, 15 Apr 2024 15:10:04 -0700 Subject: [PATCH 3/4] clarify that tsdownsample must be installed for alt algos --- hvplot/converter.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hvplot/converter.py b/hvplot/converter.py index c2997a382..a6470be95 100644 --- a/hvplot/converter.py +++ b/hvplot/converter.py @@ -209,19 +209,23 @@ class HoloViewsConverter: Controls the application of downsampling to the plotted data, which is particularly useful for large timeseries datasets to reduce the amount of data sent to browser and improve - visualization performance. Requires HoloViews >= 1.16. Acceptable - values: - False: No downsampling is applied. - True: Applies - downsampling using HoloViews' default algorithm + visualization performance. Requires HoloViews >= 1.16. Additional + dependencies: Installing the `tsdownsampler` library is required + for using any downsampling methods other than the default 'lttb'. + Acceptable values: + - False: No downsampling is applied. + - True: Applies downsampling using HoloViews' default algorithm (LTTB - Largest Triangle Three Buckets). - 'lttb': Explicitly applies the Largest Triangle Three Buckets algorithm. - 'minmax': Applies the MinMax algorithm, selecting the minimum - and maximum values in each bin. + and maximum values in each bin. Requires `tsdownsampler`. - 'm4': Applies the M4 algorithm, selecting the minimum, maximum, - first, and last values in each bin. + first, and last values in each bin. Requires `tsdownsampler`. - 'minmax-lttb': Combines MinMax and LTTB algorithms for downsampling, first applying MinMax to reduce to a preliminary - set of points, then LTTB for further reduction. + set of points, then LTTB for further reduction. Requires + `tsdownsampler`. Other string values corresponding to supported algorithms in HoloViews may also be used. dynspread (default=False): From 56d3b5411856b229e753946d9aec69fb4e57fc5d Mon Sep 17 00:00:00 2001 From: Demetris Roumis Date: Mon, 15 Apr 2024 15:10:31 -0700 Subject: [PATCH 4/4] fix name of lib --- hvplot/converter.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hvplot/converter.py b/hvplot/converter.py index a6470be95..57ea9b751 100644 --- a/hvplot/converter.py +++ b/hvplot/converter.py @@ -210,7 +210,7 @@ class HoloViewsConverter: which is particularly useful for large timeseries datasets to reduce the amount of data sent to browser and improve visualization performance. Requires HoloViews >= 1.16. Additional - dependencies: Installing the `tsdownsampler` library is required + dependencies: Installing the `tsdownsample` library is required for using any downsampling methods other than the default 'lttb'. Acceptable values: - False: No downsampling is applied. @@ -219,13 +219,13 @@ class HoloViewsConverter: - 'lttb': Explicitly applies the Largest Triangle Three Buckets algorithm. - 'minmax': Applies the MinMax algorithm, selecting the minimum - and maximum values in each bin. Requires `tsdownsampler`. + and maximum values in each bin. Requires `tsdownsample`. - 'm4': Applies the M4 algorithm, selecting the minimum, maximum, - first, and last values in each bin. Requires `tsdownsampler`. + first, and last values in each bin. Requires `tsdownsample`. - 'minmax-lttb': Combines MinMax and LTTB algorithms for downsampling, first applying MinMax to reduce to a preliminary set of points, then LTTB for further reduction. Requires - `tsdownsampler`. + `tsdownsample`. Other string values corresponding to supported algorithms in HoloViews may also be used. dynspread (default=False):