API

Entry Points

Canvas

Canvas([plot_width, plot_height, x_range, …])

An abstract canvas representing the space in which to bin.

Canvas.line(self, source, x, y[, agg, axis])

Compute a reduction by pixel, mapping data to pixels as one or more lines.

Canvas.points(self, source, x, y[, agg])

Compute a reduction by pixel, mapping data to pixels as points.

Canvas.raster(self, source[, layer, …])

Sample a raster dataset by canvas size and bounds.

Canvas.trimesh(self, vertices, simplices[, …])

Compute a reduction by pixel, mapping data to pixels as a triangle.

Canvas.validate(self)

Check that parameter settings are valid for this object

Pipeline

Pipeline(df, glyph[, agg, transform_fn, …])

A datashading pipeline callback.

Edge Bundling

directly_connect_edges

alias of datashader.bundling.connect_edges

hammer_bundle(**params)

Iteratively group edges and return as paths suitable for datashading.

Glyphs

Point

Point(x, y)

A point, with center at x and y.

Point.inputs

Point.validate(self, in_dshape)

Line

Line

Line.inputs

Line.validate

Reductions

any([column])

Whether any elements in column map to each bin.

count([column])

Count elements in each bin.

count_cat([column])

Count of all elements in column, grouped by category.

first([column])

First value encountered in column.

last([column])

Last value encountered in column.

m2([column])

Sum of square differences from the mean of all elements in column.

max([column])

Maximum value of all elements in column.

mean([column])

Mean of all elements in column.

min([column])

Minimum value of all elements in column.

mode([column])

Mode (most common value) of all the values encountered in column.

std([column])

Standard Deviation of all elements in column.

sum([column])

Sum of all elements in column.

summary(**kwargs)

A collection of named reductions.

var([column])

Variance of all elements in column.

Transfer Functions

Image

Image([data, coords, dims, name, attrs, …])

Attributes

Image.to_bytesio(self[, format, origin])

Image.to_pil(self[, origin])

Images

Images(*images)

A list of HTML-representable objects to display in a table.

Images.cols(self, n)

Set the number of columns to use in the HTML table.

Other

dynspread(img[, threshold, max_px, shape, …])

Spread pixels in an image dynamically based on the image density.

set_background(img[, color, name])

Return a new image, with the background set to color.

shade(agg[, cmap, color_key, how, alpha, …])

Convert a DataArray to an image by choosing an RGBA pixel color for each value.

spread(img[, px, shape, how, mask, name])

Spread pixels in an image.

stack(\*imgs, \*\*kwargs)

Combine images together, overlaying later images onto earlier ones.

Definitions

class datashader.Canvas(plot_width=600, plot_height=600, x_range=None, y_range=None, x_axis_type='linear', y_axis_type='linear')[source]

An abstract canvas representing the space in which to bin.

Parameters
plot_width, plot_heightint, optional

Width and height of the output aggregate in pixels.

x_range, y_rangetuple, optional

A tuple representing the bounds inclusive space [min, max] along the axis.

x_axis_type, y_axis_typestr, optional

The type of the axis. Valid options are 'linear' [default], and 'log'.

Methods

area(self, source, x, y[, agg, axis, y_stack])

Compute a reduction by pixel, mapping data to pixels as a filled area region

line(self, source, x, y[, agg, axis])

Compute a reduction by pixel, mapping data to pixels as one or more lines.

points(self, source, x, y[, agg])

Compute a reduction by pixel, mapping data to pixels as points.

quadmesh(self, source[, x, y, agg])

Samples a recti- or curvi-linear quadmesh by canvas size and bounds.

raster(self, source[, layer, …])

Sample a raster dataset by canvas size and bounds.

trimesh(self, vertices, simplices[, mesh, …])

Compute a reduction by pixel, mapping data to pixels as a triangle.

validate(self)

Check that parameter settings are valid for this object

class datashader.Pipeline(df, glyph, agg=<datashader.reductions.count object>, transform_fn=<function identity>, color_fn=<function shade>, spread_fn=<function dynspread>, width_scale=1.0, height_scale=1.0)[source]

A datashading pipeline callback.

Given a declarative specification, creates a callable with the following signature:

callback(x_range, y_range, width, height)

where x_range and y_range form the bounding box on the viewport, and width and height specify the output image dimensions.

Parameters
dfpandas.DataFrame, dask.DataFrame
glyphGlyph

The glyph to bin by.

aggReduction, optional

The reduction to compute per-pixel. Default is count().

transform_fncallable, optional

A callable that takes the computed aggregate as an argument, and returns another aggregate. This can be used to do preprocessing before passing to the color_fn function.

color_fncallable, optional

A callable that takes the output of tranform_fn, and returns an Image object. Default is shade.

spread_fncallable, optional

A callable that takes the output of color_fn, and returns another Image object. Default is dynspread.

height_scale: float, optional

Factor by which to scale the provided height

width_scale: float, optional

Factor by which to scale the provided width

Methods

__call__(self[, x_range, y_range, width, height])

Compute an image from the specified pipeline.

datashader.bundling.directly_connect_edges

alias of datashader.bundling.connect_edges

class datashader.bundling.hammer_bundle(**params)[source]

Iteratively group edges and return as paths suitable for datashading.

Breaks each edge into a path with multiple line segments, and iteratively curves this path to bundle edges into groups.

Methods

__call__(self, nodes, edges, \*\*params)

Convert a graph data structure into a path structure for plotting

debug(\*args, \*\*kwargs)

Inspect .param.debug method for the full docstring

defaults(\*args, \*\*kwargs)

Inspect .param.defaults method for the full docstring

force_new_dynamic_value(\*args, \*\*kwargs)

get_param_values(\*args, \*\*kwargs)

get_value_generator(\*args, \*\*kwargs)

inspect_value(\*args, \*\*kwargs)

instance(self_or_cls, \*\*params)

message(\*args, \*\*kwargs)

Inspect .param.message method for the full docstring

params(\*args, \*\*kwargs)

pprint(self[, imports, prefix, …])

Same as Parameterized.pprint, except that X.classname(Y is replaced with X.classname.instance(Y

print_param_defaults(\*args, \*\*kwargs)

Inspect .param.print_param_defaults method for the full docstring

print_param_values(\*args, \*\*kwargs)

Inspect .param.print_param_values method for the full docstring

script_repr(self[, imports, prefix])

Same as Parameterized.script_repr, except that X.classname(Y is replaced with X.classname.instance(Y

set_default(\*args, \*\*kwargs)

Inspect .param.set_default method for the full docstring

set_dynamic_time_fn(\*args, \*\*kwargs)

set_param(\*args, \*\*kwargs)

state_pop(self)

Restore the most recently saved state.

state_push(self)

Save this instance’s state.

verbose(\*args, \*\*kwargs)

Inspect .param.verbose method for the full docstring

warning(\*args, \*\*kwargs)

Inspect .param.warning method for the full docstring

x = param.String(default=’x’)

Column name for each node’s x coordinate.

y = param.String(default=’y’)

Column name for each node’s y coordinate.

source = param.String(default=’source’)

Column name for each edge’s source.

target = param.String(default=’target’)

Column name for each edge’s target.

weight = param.String(default=’weight’)

Column name for each edge weight. If None, weights are ignored.

include_edge_id = param.Boolean(bounds=(0, 1), default=False)

Include edge IDs in bundled dataframe

initial_bandwidth = param.Number(bounds=(0.0, None), default=0.05, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Initial value of the bandwidth….

decay = param.Number(bounds=(0.0, 1.0), default=0.7, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Rate of decay in the bandwidth value, with 1.0 indicating no decay.

iterations = param.Integer(bounds=(1, None), default=4, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Number of passes for the smoothing algorithm

batch_size = param.Integer(bounds=(1, None), default=20000, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Number of edges to process together

tension = param.Number(bounds=(0, None), default=0.3, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Exponential smoothing factor to use when smoothing

accuracy = param.Integer(bounds=(1, None), default=500, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Number of entries in table for…

advect_iterations = param.Integer(bounds=(0, None), default=50, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Number of iterations to move edges along gradients

min_segment_length = param.Number(bounds=(0, None), default=0.008, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Minimum length (in data space?) for an edge segment

max_segment_length = param.Number(bounds=(0, None), default=0.016, inclusive_bounds=(True, True), time_dependent=False, time_fn=Time(label=’Time’, name=’Time00001’, time_type=<class ‘int’>, timestep=1.0, unit=None, until=Infinity()))

Maximum length (in data space?) for an edge segment

class datashader.glyphs.Point(x, y)[source]

A point, with center at x and y.

Points map each record to a single bin. Points falling exactly on the upper bounds are treated as a special case, mapping into the previous bin rather than being cropped off.

Parameters
x, ystr

Column names for the x and y coordinates of each point.

Attributes
inputs
ndims

The number of dimensions required in the data structure this Glyph is constructed from.

x_label
y_label

Methods

expand_aggs_and_cols(self, append)

Create a decorator that can be used on functions that accept *aggs_and_cols as a variable length argument.The decorator will replace *aggs_and_cols with a fixed number of arguments..

compute_bounds_dask

compute_x_bounds

compute_y_bounds

maybe_expand_bounds

required_columns

validate

class datashader.reductions.any(column=None)[source]

Whether any elements in column map to each bin.

Parameters
columnstr, optional

If provided, only elements in column that are NaN are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.count(column=None)[source]

Count elements in each bin.

Parameters
columnstr, optional

If provided, only counts elements in column that are not NaN. Otherwise, counts every element.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.count_cat(column=None)[source]

Count of all elements in column, grouped by category.

Parameters
columnstr

Name of the column to aggregate over. Column data type must be categorical. Resulting aggregate has a outer dimension axis along the categories present.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.first(column=None)[source]

First value encountered in column.

Useful for categorical data where an actual value must always be returned, not an average or other numerical calculation.

Currently only supported for rasters, externally to this class.

Parameters
columnstr

Name of the column to aggregate over. If the data type is floating point, NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.last(column=None)[source]

Last value encountered in column.

Useful for categorical data where an actual value must always be returned, not an average or other numerical calculation.

Currently only supported for rasters, externally to this class.

Parameters
columnstr

Name of the column to aggregate over. If the data type is floating point, NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.m2(column=None)[source]

Sum of square differences from the mean of all elements in column.

Intermediate value for computing var and std, not intended to be used on its own.

Parameters
columnstr

Name of the column to aggregate over. Column data type must be numeric. NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.max(column=None)[source]

Maximum value of all elements in column.

Parameters
columnstr

Name of the column to aggregate over. Column data type must be numeric. NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.mean(column=None)[source]

Mean of all elements in column.

Parameters
columnstr

Name of the column to aggregate over. Column data type must be numeric. NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.min(column=None)[source]

Minimum value of all elements in column.

Parameters
columnstr

Name of the column to aggregate over. Column data type must be numeric. NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.mode(column=None)[source]

Mode (most common value) of all the values encountered in column.

Useful for categorical data where an actual value must always be returned, not an average or other numerical calculation.

Currently only supported for rasters, externally to this class. Implementing it for other glyph types would be difficult due to potentially unbounded data storage requirements to store indefinite point or line data per pixel.

Parameters
columnstr

Name of the column to aggregate over. If the data type is floating point, NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.std(column=None)[source]

Standard Deviation of all elements in column.

Parameters
columnstr

Name of the column to aggregate over. Column data type must be numeric. NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.sum(column=None)[source]

Sum of all elements in column.

Elements of resulting aggregate are nan if they are not updated.

Parameters
columnstr

Name of the column to aggregate over. Column data type must be numeric. NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.summary(**kwargs)[source]

A collection of named reductions.

Computes all aggregates simultaneously, output is stored as a xarray.Dataset.

Examples

A reduction for computing the mean of column “a”, and the sum of column “b” for each bin, all in a single pass.

>>> import datashader as ds
>>> red = ds.summary(mean_a=ds.mean('a'), sum_b=ds.sum('b'))
Attributes
inputs

Methods

out_dshape

validate

class datashader.reductions.var(column=None)[source]

Variance of all elements in column.

Parameters
columnstr

Name of the column to aggregate over. Column data type must be numeric. NaN values in the column are skipped.

Attributes
inputs

Methods

out_dshape

validate

class datashader.transfer_functions.Image(data: Any = <NA>, coords: Union[Sequence[Tuple], Mapping[collections.abc.Hashable, Any], None] = None, dims: collections.abc.Hashable = None, name: collections.abc.Hashable = None, attrs: Mapping = None, encoding=None, indexes=None, fastpath: bool = False)[source]
Attributes
T
attrs

Dictionary storing arbitrary metadata with this array.

chunks

Block dimensions for this array’s data or None if it’s not a dask array.

coords

Dictionary-like container of coordinate arrays.

data

The array’s data as a dask or numpy array

dims

Tuple of dimension names associated with this array.

dt

Access datetime fields for DataArrays with datetime-like dtypes.

dtype
encoding

Dictionary of format-specific settings for how this array should be serialized.

imag
indexes

Mapping of pandas.Index objects used for label based indexing

loc

Attribute for location based indexing like pandas.

name

The name of this array.

nbytes
ndim
plot

Access plotting functions

real
shape
size
sizes

Ordered mapping from dimension names to lengths.

str

Vectorized string functions for string-like arrays.

values

The array’s data as a numpy.ndarray

variable

Low level interface to the Variable object for this DataArray.

Methods

all(self[, dim, axis])

Reduce this DataArray’s data by applying all along some dimension(s).

any(self[, dim, axis])

Reduce this DataArray’s data by applying any along some dimension(s).

argmax(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying argmax along some dimension(s).

argmin(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying argmin along some dimension(s).

argsort([axis, kind, order])

Returns the indices that would sort this array.

assign_attrs(self, \*args, \*\*kwargs)

Assign new attrs to this object.

assign_coords(self[, coords])

Assign new coordinates to this object.

astype(dtype[, order, casting, subok, copy])

Copy of the array, cast to a specified type.

bfill(self, dim, limit)

Fill NaN values by propogating values backward

broadcast_equals(self, other)

Two DataArrays are broadcast equal if they are equal after broadcasting them against each other such that they have the same dimensions.

broadcast_like(self, other, …)

Broadcast this DataArray against another Dataset or DataArray.

chunk(self, chunks, numbers.Number, …)

Coerce this array’s data into a dask arrays with the given chunks.

clip([min, max, out])

Return an array whose values are limited to [min, max].

close(self)

Close any files linked to this object

coarsen(self, dim, int]=None, boundary, …)

Coarsen object.

combine_first(self, other)

Combine two DataArray objects, with union of coordinates.

compute(self, \*\*kwargs)

Manually trigger loading of this array’s data from disk or a remote source into memory and return a new array.

conj()

Complex-conjugate all elements.

conjugate()

Return the complex conjugate, element-wise.

copy(self, deep, data)

Returns a copy of this array.

count(self[, dim, axis])

Reduce this DataArray’s data by applying count along some dimension(s).

cumprod(self[, dim, axis, skipna])

Apply cumprod along some dimension of DataArray.

cumsum(self[, dim, axis, skipna])

Apply cumsum along some dimension of DataArray.

diff(self, dim, n, label)

Calculate the n-th order discrete difference along given axis.

differentiate(self, coord, edge_order, …)

Differentiate the array with the second order accurate central differences.

dot(self, other, dims)

Perform dot product of two DataArrays along their shared dims.

drop(self, labels[, dim, errors])

Drop coordinates or index labels from this DataArray.

dropna(self, dim, how, thresh)

Returns a new array with dropped labels for missing values along the provided dimension.

equals(self, other)

True if two DataArrays have the same dimensions, coordinates and values; otherwise False.

expand_dims(self, dim, …[, axis])

Return a new object with an additional axis (or axes) inserted at the corresponding position in the array shape.

ffill(self, dim, limit)

Fill NaN values by propogating values forward

fillna(self, value)

Fill missing values in this object.

from_cdms2(variable)

Convert a cdms2.Variable into an xarray.DataArray

from_dict(d)

Convert a dictionary into an xarray.DataArray

from_iris(cube)

Convert a iris.cube.Cube into an xarray.DataArray

from_series(series, sparse)

Convert a pandas.Series into an xarray.DataArray.

get_axis_num(self, dim)

Return axis number(s) corresponding to dimension(s) in this array.

get_index(self, key)

Get an index for a dimension, with fall-back to a default RangeIndex

groupby(self, group, squeeze, restore_coord_dims)

Returns a GroupBy object for performing grouped operations.

groupby_bins(self, group, bins, right[, labels])

Returns a GroupBy object for performing grouped operations.

head(self, indexers, int], int]=None, …)

Return a new DataArray whose data is given by the the first n values along the specified dimension(s).

identical(self, other)

Like equals, but also checks the array name and attributes, and attributes on all coordinates.

integrate(self, dim, datetime_unit)

integrate the array with the trapezoidal rule.

interp(self, coords, Any]=None, method, …)

Multidimensional interpolation of variables.

interp_like(self, other, …)

Interpolate this object onto the coordinates of another object, filling out of range values with NaN.

interpolate_na(self[, dim])

Interpolate values according to different methods.

isel(self, indexers, Any]=None, drop, …)

Return a new DataArray whose data is given by integer indexing along the specified dimension(s).

isin(self, test_elements)

Tests each value in the array for whether it is in test elements.

item(*args)

Copy an element of an array to a standard Python scalar and return it.

load(self, \*\*kwargs)

Manually trigger loading of this array’s data from disk or a remote source into memory and return this array.

max(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying max along some dimension(s).

mean(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying mean along some dimension(s).

median(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying median along some dimension(s).

min(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying min along some dimension(s).

persist(self, \*\*kwargs)

Trigger computation in constituent dask arrays

pipe(self, func, ~T], Tuple[Callable[…, …)

Apply func(self, *args, **kwargs)

prod(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying prod along some dimension(s).

quantile(self, q, dim, interpolation, keep_attrs)

Compute the qth quantile of the data along the specified dimension.

rank(self, dim, pct, keep_attrs)

Ranks the data.

reduce(self, func, Any], dim, axis, int, …)

Reduce this array by applying func along some dimension(s).

reindex(self, indexers, Any]=None, method[, …])

Conform this object onto the indexes of another object, filling in missing values with fill_value.

reindex_like(self, other, …[, tolerance, …])

Conform this object onto the indexes of another object, filling in missing values with fill_value.

rename(self, new_name_or_name_dict, …)

Returns a new DataArray with renamed coordinates or a new name.

reorder_levels(self, dim_order, …)

Rearrange index levels using input order.

resample(self, indexer, str]=None[, skipna, …])

Returns a Resample object for performing resampling operations.

reset_coords(self, names, drop, inplace)

Given names of coordinates, reset them to become variables.

reset_index(self, dims_or_levels, drop, inplace)

Reset the specified index(es) or multi-index level(s).

roll(self, shifts, int]=None, roll_coords, …)

Roll this array by an offset along one or more dimensions.

rolling(self, dim, int]=None, min_periods, …)

Rolling window object.

rolling_exp(self, window, int]=None, …)

Exponentially-weighted moving window.

searchsorted(v[, side, sorter])

Find indices where elements of v should be inserted in a to maintain order.

sel(self, indexers, Any]=None, method[, …])

Return a new DataArray whose data is given by selecting index labels along the specified dimension(s).

set_index(self, indexes, …)

Set DataArray (multi-)indexes using one or more existing coordinates.

shift(self, shifts, int]=None, fill_value, …)

Shift this array by an offset along one or more dimensions.

sortby(self, variables, _ForwardRef], ascending)

Sort object by labels or values (along an axis).

squeeze(self, dim, drop, axis, …)

Return a new object with squeezed data.

stack(self, dimensions, …)

Stack any number of existing dimensions into a single new dimension.

std(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying std along some dimension(s).

sum(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying sum along some dimension(s).

swap_dims(self, dims_dict, …)

Returns a new DataArray with swapped dimensions.

tail(self, indexers, int], int]=None, …)

Return a new DataArray whose data is given by the the last n values along the specified dimension(s).

thin(self, indexers, int], int]=None, …)

Return a new DataArray whose data is given by each n value along the specified dimension(s).

to_cdms2(self)

Convert this array into a cdms2.Variable

to_dataframe(self, name)

Convert this array and its coordinates into a tidy pandas.DataFrame.

to_dataset(self, dim, \*, name)

Convert a DataArray to a Dataset.

to_dict(self, data)

Convert this xarray.DataArray into a dictionary following xarray naming conventions.

to_index(self)

Convert this variable to a pandas.Index.

to_iris(self)

Convert this array into a iris.cube.Cube

to_masked_array(self, copy)

Convert this array into a numpy.ma.MaskedArray

to_netcdf(self, \*args, \*\*kwargs)

Write DataArray contents to a netCDF file.

to_pandas(self)

Convert this array into a pandas object with the same shape.

to_series(self)

Convert this array into a pandas.Series.

to_unstacked_dataset(self, dim[, level])

Unstack DataArray expanding to Dataset along a given level of a stacked coordinate.

transpose(self, \*dims, transpose_coords)

Return a new DataArray object with transposed dimensions.

unstack(self, dim)

Unstack existing dimensions corresponding to MultiIndexes into multiple new dimensions.

var(self[, dim, axis, skipna])

Reduce this DataArray’s data by applying var along some dimension(s).

where(self, cond[, other])

Filter elements from this object according to a condition.

isnull

notnull

round

to_bytesio

to_pil

datashader.transfer_functions.stack(*imgs, **kwargs)[source]

Combine images together, overlaying later images onto earlier ones.

Parameters
imgsiterable of Image

The images to combine.

howstr, optional

The compositing operator to combine pixels. Default is ‘over’.

datashader.transfer_functions.shade(agg, cmap=['lightblue', 'darkblue'], color_key=['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999', '#66c2a5', '#fc8d62', '#8da0cb', '#a6d854', '#ffd92f', '#e5c494', '#ffffb3', '#fb8072', '#fdb462', '#fccde5', '#d9d9d9', '#ccebc5', '#ffed6f'], how='eq_hist', alpha=255, min_alpha=40, span=None, name=None)[source]

Convert a DataArray to an image by choosing an RGBA pixel color for each value.

Requires a DataArray with a single data dimension, here called the “value”, indexed using either 2D or 3D coordinates.

For a DataArray with 2D coordinates, the RGB channels are computed from the values by interpolated lookup into the given colormap cmap. The A channel is then set to the given fixed alpha value for all non-zero values, and to zero for all zero values.

DataArrays with 3D coordinates are expected to contain values distributed over different categories that are indexed by the additional coordinate. Such an array would reduce to the 2D-coordinate case if collapsed across the categories (e.g. if one did aggc.sum(dim='cat') for a categorical dimension cat). The RGB channels for the uncollapsed, 3D case are computed by averaging the colors in the provided color_key (with one color per category), weighted by the array’s value for that category. The A channel is then computed from the array’s total value collapsed across all categories at that location, ranging from the specified min_alpha to the maximum alpha value (255).

Parameters
aggDataArray
cmaplist of colors or matplotlib.colors.Colormap, optional

The colormap to use for 2D agg arrays. Can be either a list of colors (specified either by name, RGBA hexcode, or as a tuple of (red, green, blue) values.), or a matplotlib colormap object. Default is ["lightblue", "darkblue"].

color_keydict or iterable

The colors to use for a 3D (categorical) agg array. Can be either a dict mapping from field name to colors, or an iterable of colors in the same order as the record fields, and including at least that many distinct colors.

howstr or callable, optional

The interpolation method to use, for the cmap of a 2D DataArray or the alpha channel of a 3D DataArray. Valid strings are ‘eq_hist’ [default], ‘cbrt’ (cube root), ‘log’ (logarithmic), and ‘linear’. Callables take 2 arguments - a 2-dimensional array of magnitudes at each pixel, and a boolean mask array indicating missingness. They should return a numeric array of the same shape, with NaN values where the mask was True.

alphaint, optional

Value between 0 - 255 representing the alpha value to use for colormapped pixels that contain data (i.e. non-NaN values). Regardless of this value, NaN values are set to be fully transparent when doing colormapping.

min_alphafloat, optional

The minimum alpha value to use for non-empty pixels when doing colormapping, in [0, 255]. Use a higher value to avoid undersaturation, i.e. poorly visible low-value datapoints, at the expense of the overall dynamic range.

spanlist of min-max range, optional

Min and max data values to use for colormap interpolation, when wishing to override autoranging.

namestring name, optional

Optional string name to give to the Image object to return, to label results for display.

datashader.transfer_functions.set_background(img, color=None, name=None)[source]

Return a new image, with the background set to color.

Parameters
imgImage
colorcolor name or tuple, optional

The background color. Can be specified either by name, hexcode, or as a tuple of (red, green, blue) values.

datashader.transfer_functions.spread(img, px=1, shape='circle', how='over', mask=None, name=None)[source]

Spread pixels in an image.

Spreading expands each pixel a certain number of pixels on all sides according to a given shape, merging pixels using a specified compositing operator. This can be useful to make sparse plots more visible.

Parameters
imgImage
pxint, optional

Number of pixels to spread on all sides

shapestr, optional

The shape to spread by. Options are ‘circle’ [default] or ‘square’.

howstr, optional

The name of the compositing operator to use when combining pixels.

maskndarray, shape (M, M), optional

The mask to spread over. If provided, this mask is used instead of generating one based on px and shape. Must be a square array with odd dimensions. Pixels are spread from the center of the mask to locations where the mask is True.

namestring name, optional

Optional string name to give to the Image object to return, to label results for display.

datashader.transfer_functions.dynspread(img, threshold=0.5, max_px=3, shape='circle', how='over', name=None)[source]

Spread pixels in an image dynamically based on the image density.

Spreading expands each pixel a certain number of pixels on all sides according to a given shape, merging pixels using a specified compositing operator. This can be useful to make sparse plots more visible. Dynamic spreading determines how many pixels to spread based on a density heuristic. Spreading starts at 1 pixel, and stops when the fraction of adjacent non-empty pixels reaches the specified threshold, or the max_px is reached, whichever comes first.

Parameters
imgImage
thresholdfloat, optional

A tuning parameter in [0, 1], with higher values giving more spreading.

max_pxint, optional

Maximum number of pixels to spread on all sides.

shapestr, optional

The shape to spread by. Options are ‘circle’ [default] or ‘square’.

howstr, optional

The name of the compositing operator to use when combining pixels.