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

Adding hover_data argument to FF.create_trisurf()?

Hey everyone, just started using the library and have been really enjoying it so far!

Quick question - I am currently plotting a sphere via FF.create_trisurf() with custom colors specified via a list in color_func parameter. I would like these values to be also available when I hover on the surface, on top of the already displayed x, y, z coordinates - is this by any chance possible? If so, could I add any other arbitrary values to the hover list? How so?

Thanks in advance :slight_smile:

Hi @Adrian,

Welcome to Plotly forum!
ff.create_trisurf() is an old method to plot trisurfs, and no more mantained. Plotly provides the Mesh3d chart type instead: https://plotly.com/~empet/15522/trisurfs-defined-by-mesh3d/#/

Thanks @empet, good to know!

I managed to get it to work by adding the following to the Mesh3d:

    hovertemplate = """
    x: %{x:.2f}<br>
    y: %{y:.2f}<br>
    z: %{z:.2f}<br>
    val: %{text}
    """
    fig = FF.create_trisurf(x=x_interp.flatten(), y=y_interp.flatten(), z=z_interp.flatten(),
                             colormap=cmap,
                             simplices=s,
                             color_func=s_color,
                             title="sphere",
                             plot_edges=False
                            )
    result =  fig.data[0]  # a Mesh3d object
    result.text = [f"{item:.2f}" for item in s_color]
    result.hovertemplate = hovertemplate

Of course the same approach could be used directly for the Mesh3d object. Will accept this as a solution but if there is a better way of doing this, please let me know and I’ll change it to something else :slight_smile: