Tota
Tota

Reputation: 11

HeatMap in Holoviews?

I'm trying to plot a HeatMap with Holoviews. I've made several attempts but no success. I plot data that have 2 values (one on the axis "x" and one on the "y") and I would like each color to represent the quantity (like a histogram in a HeatMap).

Upvotes: 1

Views: 1088

Answers (1)

philippjfr
philippjfr

Reputation: 4080

In HoloViews a HeatMap is really for categorical data. If your data is numerical you really want to compute a 2D histogram and use the hv.Image elemnt, you can do this with np.histogram2d, e.g:

a, b = np.random.randn(1000, 2).T
df = pd.DataFrame({'a': a*10, 'b': b}, columns=['a', 'b'])
z, a, b = np.histogram2d(df['a'], df['b'])
hv.Image((a, b, z), ['a', 'b'], 'Count')

enter image description here

Or if you have a lot of data you can use inbuilt datashader support to do the same thing:

from holoviews.operation.datashader import rasterize

a, b = np.random.randn(1000, 2).T
df = pd.DataFrame({'a': a*10, 'b': b}, columns=['a', 'b'])
rasterize(hv.Scatter(df), width=10, height=10, dynamic=False)

Adjust width and height to your needs or remove dynamic=False to dynamically resample as you zoom.

Upvotes: 3

Related Questions