Hi. I’m trying to plot a grid with one categorical axis and one datetime axis. I’ve tried doing that using the xarray interface but it doesn’t seem to work, I get TypeError: cannot perform reduce with flexible type, because of the categorical dimension.
Another approach I tried is converting the categorical axis to integers, but then I’m not sure how to fix the ticks and the hover tool to show the actual categories.
What’s the best way to do this?
import xarray as xr
import holoviews as hv
import pandas as pd
import numpy as np
x = xr.DataArray(
data=np.random.rand(3, 5), dims=("id", "date"),
coords={
"id": ["a", "b", "c"],
"date": pd.date_range("2022-01-01", periods=5, freq="D").values.astype('<M8[ns]')
})
hv.Image(x).opts(
tools='hover',
)
I would say that the exception is the issue, or at least part of it. The exception you get is generated because hv.Image cannot set the bounds for the id axis, which is categorical (a list of strings).
One approach to overcome that issue is to set the x dimension do an integer range, like @ea42gh did (i.e., pass range(len(x.id)) as the y-dim instead of x.id):