How to use the datashader.count 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 lmcinnes / umap / umap / plot.py View on Github external
height=height)
        elif values is not None:
            min_val = data.values.min()
            val_range = data.values.max() - min_val
            data['val_cat'] = pd.Categorical((data.values - min_val) //
                                             (val_range // 256))
            point_plot = hv.Points(data, kdims=['x', 'y'], vdims=['val_cat'])
            plot = hd.datashade(point_plot,
                                aggregator=ds.count_cat('val_cat'),
                                cmap=plt.get_cmap(cmap),
                                width=width,
                                height=height)
        else:
            point_plot = hv.Points(data, kdims=['x', 'y'])
            plot = hd.datashade(point_plot,
                                aggregator=ds.count(),
                                cmap=plt.get_cmap(cmap),
                                width=width,
                                height=height)

    return plot
github holoviz / datashader / examples / dashboard / dashboard.py View on Github external
def __init__(self, config_file, outofcore, app_port):

        self.load_config_file(config_file)
        self.plot_height = 600
        self.plot_width = 990

        self.aggregate_functions = OrderedDict()
        self.aggregate_functions['Count'] = ds.count
        self.aggregate_functions['Mean'] = ds.mean
        self.aggregate_functions['Sum'] = ds.sum
        self.aggregate_functions['Min'] = ds.min
        self.aggregate_functions['Max'] = ds.max
        self.agg_function_name = list(self.aggregate_functions.keys())[0]

        # transfer function configuration
        self.transfer_functions = OrderedDict()
        self.transfer_functions['Histogram Equalization'] = 'eq_hist'
        self.transfer_functions['Linear'] = 'linear'
        self.transfer_functions['Log'] = 'log'
        self.transfer_functions[u"\u221B - Cube Root"] = 'cbrt'
        self.transfer_function = list(self.transfer_functions.values())[0]

        self.basemaps = OrderedDict()
        self.basemaps['Imagery'] = ('http://server.arcgisonline.com/arcgis'
github lmcinnes / umap / umap / plot.py View on Github external
min_val, max_val = np.min(values), np.max(values)
            bin_size = (max_val - min_val) / 256.0
            data['val_cat'] = pd.Categorical(np.round((values - min_val) / bin_size).astype(np.int16))
            aggregation = canvas.points(data, 'x', 'y', agg=ds.count_cat('val_cat'))
            color_key = _to_hex(plt.get_cmap(cmap)(np.linspace(0, 1, 256)))
            result = tf.shade(aggregation, color_key=color_key, how='eq_hist')
        else:
            data['val_cat'] = pd.Categorical(values)
            aggregation = canvas.points(data, 'x', 'y', agg=ds.count_cat('val_cat'))
            color_key_cols = _to_hex(plt.get_cmap(cmap)(np.linspace(0, 1, unique_values.shape[0])))
            color_key = dict(zip(unique_values, color_key_cols))
            result = tf.shade(aggregation, color_key=color_key, how='eq_hist')

    # Color by density (default datashader option)
    else:
        aggregation = canvas.points(data, 'x', 'y', agg=ds.count())
        result = tf.shade(aggregation, cmap=plt.get_cmap(cmap))

    if background is not None:
        result = tf.set_background(result, background)

    if ax is not None:
        _embed_datashader_in_an_axis(result, ax)
        return ax
    else:
        return result
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
if element._plot_id in self._precomputed:
            x, y, data, glyph = self._precomputed[element._plot_id]
        else:
            x, y, data, glyph = self.get_agg_data(element, category)

        if self.p.precompute:
            self._precomputed[element._plot_id] = x, y, data, glyph
        (x_range, y_range), (xs, ys), (width, height), (xtype, ytype) = self._get_sampling(element, x, y)
        ((x0, x1), (y0, y1)), (xs, ys) = self._dt_transform(x_range, y_range, xs, ys, xtype, ytype)

        params = self._get_agg_params(element, x, y, agg_fn, (x0, y0, x1, y1))

        if x is None or y is None or width == 0 or height == 0:
            return self._empty_agg(element, x, y, width, height, xs, ys, agg_fn, **params)
        elif not getattr(data, 'interface', None) is DaskInterface and not len(data):
            empty_val = 0 if isinstance(agg_fn, ds.count) else np.NaN
            xarray = xr.DataArray(np.full((height, width), empty_val),
                                  dims=[y.name, x.name], coords={x.name: xs, y.name: ys})
            return self.p.element_type(xarray, **params)

        cvs = ds.Canvas(plot_width=width, plot_height=height,
                        x_range=x_range, y_range=y_range)

        dfdata = PandasInterface.as_dframe(data)
        agg = getattr(cvs, glyph)(dfdata, x.name, y.name, agg_fn)
        if 'x_axis' in agg.coords and 'y_axis' in agg.coords:
            agg = agg.rename({'x_axis': x, 'y_axis': y})
        if xtype == 'datetime':
            agg[x.name] = (agg[x.name]/1e3).astype('datetime64[us]')
        if ytype == 'datetime':
            agg[y.name] = (agg[y.name]/1e3).astype('datetime64[us]')
github holoviz / datashader / examples / streaming.py View on Github external
if not dims_data['width'] or not dims_data['height']:
        return

    plot_width = int(math.ceil(dims_data['width'][0]))
    plot_height = int(math.ceil(dims_data['height'][0]))
    x_range = (dims_data['xmin'][0], dims_data['xmax'][0])
    y_range = (dims_data['ymin'][0], dims_data['ymax'][0])

    canvas = ds.Canvas(plot_width=plot_width,
                       plot_height=plot_height,
                       x_range=x_range,
                       y_range=y_range)

    agg = canvas.points(dataframe, 'dropoff_x', 'dropoff_y',
                        ds.count('trip_distance'))

    img = tf.shade(agg, cmap=BuGn9, how='log')

    new_data = {}
    new_data['image'] = [img.data]
    new_data['x'] = [x_range[0]]
    new_data['y'] = [y_range[0]]
    new_data['dh'] = [y_range[1] - y_range[0]]
    new_data['dw'] = [x_range[1] - x_range[0]]

    image_source.stream(new_data, 1)
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
if isinstance(element, TriMesh):
            x, y = element.nodes.kdims[:2]
        else:
            x, y = element.kdims
        info = self._get_sampling(element, x, y)
        (x_range, y_range), (xs, ys), (width, height), (xtype, ytype) = info

        agg = self.p.aggregator
        interp = self.p.interpolation or None
        precompute = self.p.precompute
        if interp == 'linear': interp = 'bilinear'
        wireframe = False
        if (not (element.vdims or (isinstance(element, TriMesh) and element.nodes.vdims))) and ds_version <= '0.6.9':
            self.p.aggregator = ds.any() if isinstance(agg, ds.any) or agg == 'any' else ds.count()
            return aggregate._process(self, element, key)
        elif ((not interp and (isinstance(agg, (ds.any, ds.count)) or
                               agg in ['any', 'count']))
               or not (element.vdims or element.nodes.vdims)):
            wireframe = True
            precompute = False # TriMesh itself caches wireframe
            agg = self._get_aggregator(element) if isinstance(agg, (ds.any, ds.count)) else ds.any()
            vdim = 'Count' if isinstance(agg, ds.count) else 'Any'
        elif getattr(agg, 'column', None):
            if agg.column in element.vdims:
                vdim = element.get_dimension(agg.column)
            elif isinstance(element, TriMesh) and agg.column in element.nodes.vdims:
                vdim = element.nodes.get_dimension(agg.column)
            else:
                raise ValueError("Aggregation column %s not found on TriMesh element."
                                 % agg.column)
        else:
            if isinstance(element, TriMesh) and element.nodes.vdims:
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
agg = self.p.aggregator
        interp = self.p.interpolation or None
        precompute = self.p.precompute
        if interp == 'linear': interp = 'bilinear'
        wireframe = False
        if (not (element.vdims or (isinstance(element, TriMesh) and element.nodes.vdims))) and ds_version <= '0.6.9':
            self.p.aggregator = ds.any() if isinstance(agg, ds.any) or agg == 'any' else ds.count()
            return aggregate._process(self, element, key)
        elif ((not interp and (isinstance(agg, (ds.any, ds.count)) or
                               agg in ['any', 'count']))
               or not (element.vdims or element.nodes.vdims)):
            wireframe = True
            precompute = False # TriMesh itself caches wireframe
            agg = self._get_aggregator(element) if isinstance(agg, (ds.any, ds.count)) else ds.any()
            vdim = 'Count' if isinstance(agg, ds.count) else 'Any'
        elif getattr(agg, 'column', None):
            if agg.column in element.vdims:
                vdim = element.get_dimension(agg.column)
            elif isinstance(element, TriMesh) and agg.column in element.nodes.vdims:
                vdim = element.nodes.get_dimension(agg.column)
            else:
                raise ValueError("Aggregation column %s not found on TriMesh element."
                                 % agg.column)
        else:
            if isinstance(element, TriMesh) and element.nodes.vdims:
                vdim = element.nodes.vdims[0]
            else:
                vdim = element.vdims[0]
            agg = self._get_aggregator(element)

        if element._plot_id in self._precomputed: