I’m wondering if it is possible to apply a custom colouring to a hv.HeatMap that is based on conditions within the data. Please see example code below:
import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib from datetime import datetime import holoviews as hv from holoviews import opts from bokeh.resources import INLINE from holoviews import dim hv.extension('bokeh', 'matplotlib') pd.options.plotting.backend = 'holoviews' green = '#00FF00' amber = '#FFFF00' red = '#FF0000' Data = [['A', 'Foo', 0.2] , ['B', 'Bar', 0.9], ['C', 'Cat', 0.7]] df = pd.DataFrame(Data, columns = ['Name', 'Category', 'Value']) df['colors'] = df.apply(lambda row: green if row['Value'] >= 0.9 else amber if row['Value'] < 0.9 and row['Value'] >= 0.7 else red if row['Value'] < 0.7 else '#8A2BE2', axis = 1) df_hm = hv.HeatMap(df,kdims=['Category','Name'], vdims=['Value', 'colors']).opts(width=900, height=400, color = hv.dim('colors'), tools=['hover'])
When I run this code, the plot defaults to the standard cmap, but when I hover over the data I can see the colours that match my conditional formatting. Is there a way of making is so that I can only see the conditional colouring. I’ve tried a few different options, including passing dim into cmap, and even a list of colours into cmap. When I pass the list of colours into cmap the order of the colours does not match up with the data at all, and appears random.
I’ve attached a picutre of what I am seeing from the data I am actually working on (the hovering behaviour), I cannot share the underlying data to that example (apologies).
Appreciate any help on a fix or alternative solution.