How to use the datashader.transfer_functions.stack 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 rapidsai / cuxfilter / python / cuxfilter / charts / datashader / plots.py View on Github external
def viewInteractiveImage(x_range, y_range, w, h, data_source):
            cvs = cds.Canvas(
                plot_width=w, plot_height=h, x_range=x_range, y_range=y_range
            )
            aggs = dict(
                (_y, cvs.line(data_source, x=self.x, y=_y)) for _y in self.y
            )
            imgs = [
                tf.shade(aggs[_y], cmap=["white", color])
                for _y, color in zip(self.y, self.colors)
            ]
            return tf.stack(*imgs)
github holoviz / holoviews / holoviews / operation / datashader.py View on Github external
if not isinstance(rgb, RGB):
                raise TypeError("The stack operation expects elements of type RGB, "
                                "not '%s'." % type(rgb).__name__)
            rgb = rgb.rgb
            dims = [kd.name for kd in rgb.kdims][::-1]
            coords = {kd.name: rgb.dimension_values(kd, False)
                      for kd in rgb.kdims}
            imgs.append(tf.Image(self.uint8_to_uint32(rgb), coords=coords, dims=dims))

        try:
            imgs = xr.align(*imgs, join='exact')
        except ValueError:
            raise ValueError('RGB inputs to the stack operation could not be aligned; '
                             'ensure they share the same grid sampling.')

        stacked = tf.stack(*imgs, how=self.p.compositor)
        arr = shade.uint32_to_uint8(stacked.data)[::-1]
        data = (coords[dims[1]], coords[dims[0]], arr[:, :, 0],
                arr[:, :, 1], arr[:, :, 2])
        if arr.shape[-1] == 4:
            data = data + (arr[:, :, 3],)
        return rgb.clone(data, datatype=[rgb.interface.datatype]+rgb.datatype)
github pyviz-dev / nbsite / examples / sites / holoviews / holoviews / operation / datashader.py View on Github external
if not isinstance(rgb, RGB):
                raise TypeError('stack operation expect RGB type elements, '
                                'not %s name.' % type(rgb).__name__)
            rgb = rgb.rgb
            dims = [kd.name for kd in rgb.kdims][::-1]
            coords = {kd.name: rgb.dimension_values(kd, False)
                      for kd in rgb.kdims}
            imgs.append(tf.Image(self.uint8_to_uint32(rgb), coords=coords, dims=dims))

        try:
            imgs = xr.align(*imgs, join='exact')
        except ValueError:
            raise ValueError('RGB inputs to stack operation could not be aligned, '
                             'ensure they share the same grid sampling.')

        stacked = tf.stack(*imgs, how=self.p.compositor)
        arr = shade.uint32_to_uint8(stacked.data)[::-1]
        data = (coords[dims[1]], coords[dims[0]], arr[:, :, 0],
                arr[:, :, 1], arr[:, :, 2])
        if arr.shape[-1] == 4:
            data = data + (arr[:, :, 3],)
        return rgb.clone(data, datatype=[rgb.interface.datatype]+rgb.datatype)
github lmcinnes / umap / umap / plot.py View on Github external
warn('Hammer edge bundling is expensive for large graphs!\n'
             'This may take a long time to compute!')
        edges = bd.hammer_bundle(point_df, edge_df, weight='weight')
    else:
        raise ValueError('{} is not a recognised bundling method'.format(edge_bundling))

    edge_img = tf.shade(canvas.line(edges, 'x', 'y', agg=ds.sum('weight')),
                        cmap=plt.get_cmap(edge_cmap), how=edge_how)
    edge_img = tf.set_background(edge_img, background)

    if show_points:
        point_img = _datashade_points(points, None, labels, values, cmap, color_key,
                                      color_key_cmap, None, width, height)
        if px_size > 1:
            point_img = tf.dynspread(point_img, threshold=0.5, max_px=px_size)
        result = tf.stack(edge_img, point_img, how="over")
    else:
        result = edge_img

    font_color = _select_font_color(background)

    dpi = plt.rcParams['figure.dpi']
    fig = plt.figure(figsize=(width / dpi, height / dpi))
    ax = fig.add_subplot(111)

    _embed_datashader_in_an_axis(result, ax)

    ax.set(xticks=[], yticks=[])
    ax.text(0.99,
            0.01,
            'UMAP: n_neighbors={}, min_dist={}'.format(umap_object.n_neighbors,
                                                       umap_object.min_dist),