Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions hvplot/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,28 @@ 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. Additional
dependencies: Installing the `tsdownsample` 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. Requires `tsdownsample`.
- 'm4': Applies the M4 algorithm, selecting the minimum, maximum,
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
`tsdownsample`.
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
Expand Down Expand Up @@ -1321,6 +1340,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:
Expand Down
8 changes: 8 additions & 0 deletions hvplot/tests/testoperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_kwargs['algorithm'] == 'minmax'