holoviews
holoviews copied to clipboard
HeatMap doesn't work with datetime very well // can we specify bins?
So I have run into this issue several times where when I construct a HeatMap with gaps in the datetime dimension, the bins that are chosen are wrong. Or at least they get displayed wrong. I haven't noticed this with other dimension types, only datetime/timestamp.
This is fixed if I make sure to use continuous datetime data (but in practice I don't know of a way to ensure this from a pandas dataframe or xarray).
holoviews v1.18.3
import pandas as pd
import numpy as np
import holoviews as hv
import random
hv.extension('bokeh')
dates = pd.date_range(pd.Timestamp('2024-01-01 12:00:00'), pd.Timestamp('2024-01-01 14:00:00'), freq=pd.Timedelta('1 min'))
nums = np.linspace(0, 50, num=20)
hm = []
for d in dates[:10].union(dates[-10:]):
for n in nums:
hm.append((d, n, random.randint(0, 50)))
hv.HeatMap(hm, kdims=['date', 'num'], vdims='random').opts(tools=['hover'])
On a somewhat related note, I have several questions:
- Is there a way to specify the bins or bin sizes that HeatMap uses?
- Does anyone know of a way to fill/resample my data (DataFrame, Xarray, or holoviews Dataset) to regular time intervals (filling unsampled times with NaN) as a workaround?