Surface - remove x: y: z: prefix from hover text (Python)

Hello everybody!
I tried to to remove or replace x: y: z: prefixes from Surface hover, but goalless.
Could somebody help me?
plotly00
I need something like this:
plotly01

Current code (Python):
layout = Layout(
title=‘Title’,
autosize=True,
width=1450,
height=730,
margin=dict(
l=0,
r=0,
b=0,
t=0),
scene=Scene(
xaxis=XAxis(
title = ‘’,
),
yaxis=YAxis(
title = ‘Maturity’
),
zaxis=ZAxis(
title = ‘Yield’
),
)

)

surface = Surface(
x=list(df),
y=df.index,
z=df.as_matrix(),
showscale=False,
#hoverlabel=dict(namelength=0),
#hoverinfo=‘x+y+z’
)

fig = Figure(data = [surface], layout=layout)

camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=0.4, y=-1, z=0.2)
)
fig[‘layout’].update(
scene=dict(camera=camera),
)
py.iplot(fig)

@Roman1 You can set the text to be displayed as follows:

text=[['{:.2f}'.format(x[j])+'<br>'+'{:.2f}'.format(y[i])+'<br>'+'{:.2f}'.format(z[i,j]) for j in range(n_cols)] 
  for i in range(n_rows)]

where x, y are lists or np.arrays of shape (n_cols,), (n_rows,) and z is a list of lists or a np.array of shape (n_rows, n_cols).

in the surface definition insert:

text=text,
hoverinfo=‘text’

In your case you should define the date as a string instead of x[j].

1 Like

It works, thank you!
One small question remains.
What is default d3 formatting for numbers?
Now with string specifier “.2f” I have:
0.75 -> 0.75
0.5 -> 0.50
8 -> 8.00
16.5 -> 16.50

I can’t find appropriate format specifier for this behavior (which I need):
0.75 -> 0.75
0.5 -> 0.5
8 -> 8
16.5 -> 16.5

Use .3g instead of .2f

1 Like

How would this work for 3d scatterplot with a dataframe of 3 columns where x,y and z should in the hovertext should be replaced by the names of the columns

@Varlor With f-strings is even simpler than the solution given above a while ago:

text = [ f'name1: {x[k]}<br>name2: {y[k]}<br>name3: {z[k]}' for k in range(number_of_points)].

If you want to limit the number of digits, then you can replace {x[k]} with {round(x[k], 2)}, and analogously for y[k], z[k].