2
votes

I have generated a holoviews heatmap plot, and want to edit the labels on the heatmap for both x-axis and y-axis. The labels right now are 1,2,3 and 4 on each axis. I would like it to be replaced with a different string text for each of the 4.

I tried the following, to no avail:

holoviews_view.opts(xticks=[(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd')]) 

Any help is much appreciated.

1
Hi @SandervandenOord, your answer was very helpful and I have upvoted your answer.Lem

1 Answers

0
votes

This seems not possible yet with .opts(xticks=[]) in Holoviews/Bokeh:
https://github.com/pyviz/holoviews/issues/2128

One (difficult) way of solving this could be using the answer to this SO-question if you're on a Mac, but I don't really like it:
Changing ticks mark period in Holoviews heatmap

WORKAROUND:
I think the easiest for now would be to just change the category_names before you plot the heatmap, like so:
df['col1'] = df['col1'].replace({1: 'a', 2: 'b'})

Here's the full example code for changing category labels of a heatmap:

# import libraries
import pandas as pd
import holoviews as hv
hv.extension('bokeh', logo=False)

# create dataframe
sample_data = [(1, 1, 1), (1, 2, 10), (2, 1, 2), (2, 2, 3)]

df = pd.DataFrame(
    data=sample_data,
    columns=['col1', 'col2', 'col3'],
)

# replace original category labels with labels that you need
df['col1'] = df['col1'].replace({1: 'a', 2: 'b'})

# show plot with new category labels
hv.HeatMap(df)

Final result where original category labels 1 and 2 have been replaced on the x-axis by 'a' and 'b':
renaming category labels heatmap holoviews