I have heatmap where data plot only using go.Heatmap(z=myData, colobar=..
How can I change x , y and z label on tooltip to anything else?
Hi,
I think the documentation page on hover text and formatting should help you get started:
- Greetings, Alex
@Alexboiboi unfortunately this didnโt help. I found one post related to my problem, but I am thinking solution should me straight forward.
Hi @mtkilic,
You can specify your exact hover text by setting the heatmap traceโs text
property to a 2D array of strings and then setting the heatmapโs hoverinfo
property to 'text'
. Feel free to share a full example and a description of what you want to display in the tooltip if youโd like more help working through it.
Hope that helps!
-Jon
import plotly.io as pio
import plotly.graph_objs as go
pio.renderers.default = 'iframe'
trace = go.Heatmap(z=[[5, 7, 11], [8, 10, 12]], colorbar = dict(title='Range'))
data = [trace]
layout = go.Layout(xaxis=go.layout.XAxis(
title=go.layout.xaxis.Title(
text='Depth Axis',
)),
yaxis=go.layout.YAxis(
title=go.layout.yaxis.Title(
text='Time Axis',
)
))
f6 = go.FigureWidget(data, layout=layout)
pio.show(f6)
@jmmease I am trying to change the label. If you look at the below image, I would like to make tooltip looks like
Depth: 0
Time: 1
Range: 8
I have this solution but I think there should be easier way
for yi, yy in enumerate(z):
hovertext.append(list())
for xi, xx in enumerate(z[0]):
hovertext[-1].append('Depth: {}<br />Time: {}<br />Range: {}'.format(xi, yi, z[yi][xi]))
One reason I dont want to do above code is the Time complexity. Because I have fairly big data set.
Hi @mtkilic,
You could do this using a hovertemplate.
import plotly.io as pio
import plotly.graph_objs as go
pio.renderers.default = 'iframe'
trace = go.Heatmap(
z=[[5, 7, 11], [8, 10, 12]],
colorbar = dict(title='Range'),
hovertemplate='Depth: %{x}<br>Time: %{y}<br>Range: %{z}<extra></extra>'
)
data = [trace]
layout = go.Layout(xaxis=go.layout.XAxis(
title=go.layout.xaxis.Title(
text='Depth Axis',
)),
yaxis=go.layout.YAxis(
title=go.layout.yaxis.Title(
text='Time Axis',
)
))
f6 = go.Figure(data, layout=layout)
pio.show(f6)
Hope that helps.
-Jon
Hi @jmmease ,
This works great. Thank you!
Thank you so much. My faith in humanity has been restored!