holoviz/datashader

Support Canvas.lines of 2D xarray with common x coordinates

ianthomas23 opened this issue · 2 comments

I would like to support the xarray equivalent of LinesAxis1XConstant which has multiple lines that all share the same x coordinates. The xarray.DataArray would be 2D, one dimension would be the x dimension and the other could be anything including a string/categorical dimension. It is best illustrated by an example:

import datashader as ds
import numpy as np
import xarray as xr

xr_ds = xr.Dataset(
    data_vars=dict(
        name=(("channel", "x"), [[2, 1, 0, 1, 2], [1, 1, 1, 1, 1]]),
    ),
    coords=dict(
        channel=("channel", ['a', 'b']),
        x=("x", np.arange(5)),
    ),
)

canvas = ds.Canvas(plot_height=3, plot_width=5)
agg = canvas.line(source=xr_ds, x="x", y="name", agg=ds.count())

The x coordinates here have length 5 and the DataArray is of shape (2, 5). The output aggregation here would be something like

<xarray.DataArray (y: 3, x: 5)>
array([[0, 0, 1, 0, 0],
       [1, 2, 1, 2, 1],
       [1, 0, 0, 0, 1]], dtype=uint32)

This should support both dask and CUDA backed xarrays, and the 2D dimensions could be in either order as we do not want to force the user to do an unnecessary array transpose.

We do support some use of xarray for lines at the moment, but it is restricted to 1D x and y values.

Sounds good to me!

Closed by #1282.