How to customize the hovering text when it is another column rather than the columns introduced for axes?

Hi, I have a df with several columns, and I have a 3D plot for showing three columns. I want to customize the hovering text to show z and also another column named place
I have done the first part for the z, but I don’t understand how to do it for another column that is not one of the axes.

fig = go.Figure()
fig.add_trace(go.Scatter3d(x=df['X'], y=df['Y'], z=df['Z'], 
                           hovertemplate="<b><i>Z</i>: %{z:.2f}</b>" + "<br><b><i>%{text}</i>"),)

Hey @Peyman , I can’t verify this right now, but you might be able to use the customdata argument.

EDIT it works:

import plotly.express as px
import plotly.graph_objects as go
import pandas as pd

# datasource
df = px.data.iris()

color_dict = {1:'red',2:'blue',3:'green'}
colors = [color_dict[i] for i in df.species_id]

# create figure + trace
fig = go.Figure()
fig.add_scatter3d(
    x=df.sepal_length, 
    y=df.sepal_width, 
    z=df.petal_width,
    # here the additional data is added
    customdata=[f'text_{i}' for i in range(df.shape[0])],
    hovertemplate="<b><i>Z</i>: %{z:.2f}</b>" + "<br><b><i>%{customdata}</i>",
    mode='markers',
    marker_size=5,
    marker_color=colors
)
fig.update_layout(width=500, height=500)

creates:

2 Likes