How to use the datashader.reductions function in datashader

To help you get started, we’ve selected a few datashader examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github holoviz / hvplot / hvplot / converter.py View on Github external
opts = dict(dynamic=self.dynamic)
        if self._plot_opts.get('width') is not None:
            opts['width'] = self._plot_opts['width']
        if self._plot_opts.get('height') is not None:
            opts['height'] = self._plot_opts['height']

        if 'cmap' in self._style_opts and self.datashade:
            levels = self._plot_opts.get('color_levels')
            cmap = self._style_opts['cmap']
            if isinstance(cmap, dict):
                opts['color_key'] = cmap
            else:
                opts['cmap'] = process_cmap(cmap, levels)

        if self.by and not self.subplots:
            opts['aggregator'] = reductions.count_cat(self.by[0])
        if self.aggregator:
            agg = self.aggregator
            if isinstance(agg, basestring) and self._color_dim:
                agg = getattr(reductions, agg)(self._color_dim)
            opts['aggregator'] = agg
        elif self._color_dim:
            opts['aggregator'] = reductions.mean(self._color_dim)
        if self.precompute:
            opts['precompute'] = self.precompute
        if self.x_sampling:
            opts['x_sampling'] = self.x_sampling
        if self.y_sampling:
            opts['y_sampling'] = self.y_sampling
        if self._plot_opts.get('xlim') is not None:
            opts['x_range'] = self._plot_opts['xlim']
        if self._plot_opts.get('ylim') is not None:
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
def _get_aggregator(self, element, add_field=True):
        agg = self.p.aggregator
        if not element.vdims and agg.column is None and not isinstance(agg, (rd.count, rd.any)):
            return ds.count()
        return super(geometry_rasterize, self)._get_aggregator(element, add_field)
github holoviz / hvplot / hvplot / converter.py View on Github external
levels = self._plot_opts.get('color_levels')
            cmap = self._style_opts['cmap']
            if isinstance(cmap, dict):
                opts['color_key'] = cmap
            else:
                opts['cmap'] = process_cmap(cmap, levels)

        if self.by and not self.subplots:
            opts['aggregator'] = reductions.count_cat(self.by[0])
        if self.aggregator:
            agg = self.aggregator
            if isinstance(agg, basestring) and self._color_dim:
                agg = getattr(reductions, agg)(self._color_dim)
            opts['aggregator'] = agg
        elif self._color_dim:
            opts['aggregator'] = reductions.mean(self._color_dim)
        if self.precompute:
            opts['precompute'] = self.precompute
        if self.x_sampling:
            opts['x_sampling'] = self.x_sampling
        if self.y_sampling:
            opts['y_sampling'] = self.y_sampling
        if self._plot_opts.get('xlim') is not None:
            opts['x_range'] = self._plot_opts['xlim']
        if self._plot_opts.get('ylim') is not None:
            opts['y_range'] = self._plot_opts['ylim']
        if not self.dynamic:
            opts['dynamic'] = self.dynamic

        style = {}
        if self.datashade:
            operation = datashade
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
class AggregationOperation(ResamplingOperation):
    """
    AggregationOperation extends the ResamplingOperation defining an
    aggregator parameter used to define a datashader Reduction.
    """

    aggregator = param.ClassSelector(class_=(ds.reductions.Reduction, basestring),
                                     default=ds.count(), doc="""
        Datashader reduction function used for aggregating the data.
        The aggregator may also define a column to aggregate; if
        no column is defined the first value dimension of the element
        will be used. May also be defined as a string.""")

    _agg_methods = {
        'any':   rd.any,
        'count': rd.count,
        'first': rd.first,
        'last':  rd.last,
        'mode':  rd.mode,
        'mean':  rd.mean,
        'sum':   rd.sum,
        'var':   rd.var,
        'std':   rd.std,
        'min':   rd.min,
        'max':   rd.max
    }

    def _get_aggregator(self, element, add_field=True):
        agg = self.p.aggregator
        if isinstance(agg, basestring):
            if agg not in self._agg_methods:
github holoviz / datashader / datashader / pipeline.py View on Github external
    def __init__(self, df, glyph, agg=reductions.count(),
                 transform_fn=identity, color_fn=tf.shade, spread_fn=tf.dynspread,
                 width_scale=1.0, height_scale=1.0):
        self.df = df
        self.glyph = glyph
        self.agg = agg
        self.transform_fn = transform_fn
        self.color_fn = color_fn
        self.spread_fn = spread_fn
        self.width_scale = width_scale
        self.height_scale = height_scale
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
def _get_aggregator(self, element, add_field=True):
        agg = self.p.aggregator
        if not element.vdims and agg.column is None and not isinstance(agg, (rd.count, rd.any)):
            return ds.any()
        return super(contours_rasterize, self)._get_aggregator(element, add_field)
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
aggregators can be supplied implementing mean, max, min and other
    reduction operations.

    The bins of the aggregate are defined by the width and height and
    the x_range and y_range. If x_sampling or y_sampling are supplied
    the operation will ensure that a bin is no smaller than the minimum
    sampling distance by reducing the width and height when zoomed in
    beyond the minimum sampling distance.

    By default, the PlotSize and RangeXY streams are applied when this
    operation is used dynamically, which means that the width, height,
    x_range and y_range will automatically be set to match the inner
    dimensions of the linked plot and the ranges of the axes.
    """

    aggregator = param.ClassSelector(class_=(ds.reductions.Reduction, basestring),
                                     default=None)

    interpolation = param.ObjectSelector(
        default='bilinear', objects=['linear', 'nearest', 'bilinear', None, False], doc="""
        The interpolation method to apply during rasterization.
        Defaults to linear interpolation and None and False are aliases
        of each other.""")

    _transforms = [(Image, regrid),
                   (Polygons, geometry_rasterize),
                   (lambda x: (isinstance(x, Path) and
                               x.interface.datatype == 'spatialpandas'),
                    geometry_rasterize),
                   (TriMesh, trimesh_rasterize),
                   (QuadMesh, quadmesh_rasterize),
                   (lambda x: (isinstance(x, NdOverlay) and