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

Scatter3d "hovertemplate"


I am using plotly express to create a 3D scatter plot of document embeddings.

I would like the hover to just show me the document title, not the coordinates.

I have tried a lot of methods from the docs unsuccessfully. I thought “hovertemplate” from the documentation was the way to go, but I am getting:
TypeError: scatter_3d() got an unexpected keyword argument 'hovertemplate'

Any ideas?

@PabloRR10 In think that you have an old Plotly version because Plotly 4.5.2 provides this property for go.Scatter3d


    Template string used for rendering the information that appear
    on hover box. Note that this will override `hoverinfo`.
    Variables are inserted using %{variable}, for example "y:
    %{y}". Numbers are formatted using d3-format's syntax
    %{variable:d3-format}, for example "Price: %{y:$.2f}".
    reference/blob/master/ for details on
    the formatting syntax. Dates are formatted using d3-time-
    format's syntax %{variable|d3-time-format}, for example "Day:
    reference/blob/master/ for details on
    the date formatting syntax. The variables available in
    `hovertemplate` are the ones emitted as event data described at
    this link
    data. Additionally, every attributes that can be specified per-
    point (the ones that are `arrayOk: true`) are available.
    Anything contained in tag `<extra>` is displayed in the
    secondary box, for example "<extra>{}</extra>". To
    hide the secondary box completely, use an empty tag
    The 'hovertemplate' property is a string and must be specified as:
      - A string
      - A number that will be converted to a string
      - A tuple, list, or one-dimensional numpy array of the above

Hi @empet, thanks for the reply!

I am using plotly version 4.5.2. and I can also see that information calling the help function.

My implementation right now is like this:

fig = px.scatter_3d(
    d, x='d1', y='d2', z='d3', 
    color='cluster',     # hover_name='Title', hover_data=["ID"]) 
    hovertemplate="T: %{Title} | ID: %{ID}")

And the error is the same:

* #### File "/app/clustering__viz/", line  *275* , in  `update_umap`

hovertemplate="T: %{Title} | ID: %{ID}")

> TypeError: scatter_3d() got an unexpected keyword argument 'hovertemplate'

Does it have a different use with Plotly Express?


Before working with plotly express you should learn how works, what are the properties of a go.Figure i.e. what contains a Plotly figure:

  1. it contains data, a list of traces of different types. To get the number of traces,


then inspect each trace:[0],[1], etc to see its type (i.e. scatter, scatter3d, heatmap, etc_

  1. The second component of a plotly figure is its layout:

fig.layout creates a figure by calling a function. In your case this function is px.scatter_3d(but it isnt an instance of the class go.Scatter3d)
To find out what traces contains the fig returned by px.scatter_3d, type[0], as I mentioned above.

Let us consider this example:

import as px
df =
fig = px.scatter_3d(df, x="Joly", y="Coderre", z="Bergeron", color="winner", size="total", hover_name="district",
                  symbol="result", color_discrete_map = {"Joly": "blue", "Bergeron": "green", "Coderre":"red"})

len( is 6[0] is:

    'hoverlabel': {'namelength': 0},
    'hovertemplate': ('<b>%{hovertext}</b><br><br>win' ... 'n=%{z}<br>total=%{marker.size}'),
    'hovertext': array(['101-Bois-de-Liesse', '102-Cap-Saint-Jacques',
                        '172-Desmarchais-Crawford', '181-Peter-McGill', '182-Saint-Jacques',
                        '33-Snowdon', '34-Notre-Dame-de-Grâce', '35-Loyola', '41-du Canal',
                        '43-Fort-Rolland', '63-Jacques-Bizard'], dtype=object),
    'legendgroup': 'Joly, plurality',
    'marker': {'color': 'blue',
               'size': array([7334, 6363, 9378, 7956, 4099, 6357, 4687, 7688, 6125, 3263, 4438, 1432],
               'sizemode': 'area',
               'sizeref': 27.625,
               'symbol': 'circle'},
    'mode': 'markers',
    'name': 'Joly, plurality',
    'scene': 'scene',
    'showlegend': True,
    'x': array([3024, 2675, 3578, 2849, 1894, 2282, 1636, 3262, 2648, 1266, 1908,  690],
    'y': array([2481, 2525, 2432, 2476, 1451, 1906, 1548, 1773, 2040, 1165, 1325,  518],
    'z': array([1829, 1163, 3368, 2631,  754, 2169, 1503, 2653, 1437,  832, 1205,  224],

If you want to change the hovertemplate for this Scatter3d trace perform
an update:[0].update(hovertemplate='your new template')

and similarly for other trace types.

Hence, don’t pass hovertemplate as an argument for the function px.scatter_3d!!! hovertemplate is an attribute of `go.Scatter go.Scatter3d, go.Heatmap, go.Bar, etc