Bokeh + Holoviews Heatmap index reorder

Hello people, is there any way to re-order columns and/or rows in heatmap plotted with holoviews & bokeh?

I am trying to plot a heatmap with hvplot from a matrix (a square pandas dataframe to be precise) but can’t seem to find a way… I can plot it if I just have a dataframe with x, y, annotations columns but then the order is not guaranteed. So I am resorting to seaborn to form the matrix as I want it first and then plot it. But it would be nice if there’s already a way in holoviews.

For e.g., this is the sample of my dataframe:

df = [['night', 'daytime', 20],
 ['morning', 'morning', 880],
 ['night', 'night', 1063],
 ['NA', 'daytime', 12],
 ['evening', 'evening', 1376],
 ['NA', 'night', 7],
 ['daytime', 'evening', 123],
 ['morning', 'NA', 218],
 ['morning', 'daytime', 84],
 ['evening', 'daytime', 239]]

df = pd.DataFrame(df, columns=['cluster_1', 'cluster_2', 'size'])

and if I do df.hvplot.heatmap('cluster_2', 'cluster_1', 'size'), I get a nice heatmap as below:

but I don’t know a way of reordering the default grid. For e.g, how do I set the order ['morning', 'daytime', 'evening', 'night', 'NA'] instead?

thanks :slight_smile:

@narudarurarasya I am not really sure what you are asking to do, or having trouble with from that description. From a Bokeh point of view you have have complete control over the coordinates. I am not sure what Holoviews does, that would be a questions for the Holoview team on one of their support channels. Othwrwise, some (Bokeh) code and/or images might help clarify the question.

Hey @Bryan thanks for the suggestion. I have updated the question. Plese review :slight_smile:

Once you get ahold of the actual Bokeh plot object, you can set

p.x_range.factors = ['morning', 'daytime', 'evening', 'night', 'NA']

I don’t know how you get ahold of the actual Bokeh plot object, that’s a Holoviews question

aah, cool. Thank you :slight_smile: