Annotations for scatter 3d

Hello,

I am adding an annotation to a scatter_3d, as such:

fig.add_annotation(
    x= 5
    y=10
    z=15
    text="sometext"
)

However, it seems that there is no attribute “z”, and the result produces an error. The same is true for the .update_layout() method, specifying the annotations as a list of dictionaries.


fig.update_layout({
    "annotations": [
        {...}
    ]
})

These are the only two methods I can seem to find, and neither have worked in my case.

Does anyone know how to correctly add annotations with scatter 3d?

TIA!

I think you can’t.

A workaround could be creating a new trace with markers at the desired cordinates and set marker_color=rgba(0,0,0,0). Then use the text parameter for the actual text.

1 Like

Awesome back up, thank you.

Is there a reason the above methods do not work / am I doing anything wrong? Documentation states “z” attribute should exist, within the “update_layout” method.

Hey @plotmaster422 you made me learn something new, thanks.

It seems that you can add annotations to scatter3D, but the syntax is slightly different (annotations are stored in the scene dictionary):

import plotly.graph_objects as go

fig = go.Figure()

fig.add_trace(go.Scatter3d(
    x=[1, 2, 3],
    y=[1, 2, 3],
    z=[1, 2, 3],
    name="z",
))

fig.update_layout(
    scene=dict(
        annotations=[
        dict(
            showarrow=False,
            x=2,
            y=2,
            z=2.7,
            text="Point 1"
        )
        ]
    ),
)

fig.show()

See also here (search for 3D Annotation on this page)

mrep 3D annotations

ah this is huge. Thank you!

1 Like