1

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).

skytaker
  • 4,159
  • 1
  • 21
  • 31
Tota
  • 11
  • 4
  • Could you elaborate on what your data looks like. – philippjfr Sep 19 '19 at 14:46
  • Unfortunately I have no the code here. But the problem is that I have a Dataframe and for example I want to create a HeatMap with data['a'] and data['b'] and I want that the third component represents the quantitaty of data in which data['a'] and data['b'] have the some values – Tota Sep 19 '19 at 14:48
  • Can you put an example of your data in column a, column b and column c in your question? It really depends on what your data looks like. Is it categorical or numerical data in column a and column b? – Sander van den Oord Sep 19 '19 at 20:58
  • Just numerical data! These are like coordinate in a space 2D , so you should immagine one coloumn is the axis x and the other the axis y. The third component represent how many data I have in each point – Tota Sep 19 '19 at 21:26

1 Answers1

3

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.

philippjfr
  • 3,997
  • 14
  • 15