Black Lives Matter. Please consider donating to Black Girls Code today.

Change 'x', 'y' to something else in hover tooltip using heatmapI

I have a heatmap, and have given the x and y axes titles (‘actual’, ‘predicted’). But when I hover on the heatmap I still see ‘x’ and ‘y’ labels with the values. Is there a way to get them to change here too?

If your data for plotting the heatmap are X, Y, Z,
then you define the text to be displayed at hovering the mouse over your plot
as follows:

text=[['(actual, predicted)=('+'{:.2f}'.format(X[i])+', '+'{:.2f}'.format(Y[j])+')' for i in range(len(X)) ] 
       for j in range(len(Y))]

and the Heatmap object as:

trace=Heatmap( z=Z,  x=X,  y=Y, colorscale='your_colorscale', 
               text=text, hoverinfo='text')

I try your suggest , but ‘test’ show Error information as " Error: unexpected ‘[[’ in “text=[[”"spaces`

m <- matrix(rnorm(9), nrow = 3, ncol = 3)
text=[[’(actual, predicted)=(’+’{:.2f}’.format(X[i])+’, ‘+’{:.2f}’.format(Y[j])+’)’ for i in range(len(X)) ]
for j in range(len(Y))]
p <- plot_ly(z = m,
x = c(“a”, “b”, “c”), y = c(“d”, “e”, “f”),
type = “heatmap”)
layout(p, xaxis=list(title = “year”), yaxis=list(title=‘grp’),margin=list(l=150))