Search code examples
pythonplotlyscatter3d

How to add data (or single point) to an existing 3d scatter plotly exprees plot in python


I have a code that makes a plot similar to this one:

import plotly.express as px
import plotly.graph_objects as go
df = px.data.tips()
fig = go.Figure(data =[go.Scatter3d(x = df['total_bill'],
                                   y = df['time'],
                                   z = df['tip'],
                                   mode ='markers')])
fig.show()

I want to add a single point with different symbol and see it among the rest of the points

I have tried this

fig.add_trace(
    go.scatter3d(x=[25],
                 y=['Dinner'],
                 z=[6],
                 mode='markers')
)

and gave me: TypeError: 'module' object is not callable

Can it be done? This is what I am looking for: enter image description here


Solution

  • the problem it's a typo in your code. You used go.scatter3d instead of go.Scatter3d

    fig.add_trace(
        go.Scatter3d(x=[25],
                     y=['Dinner'],
                     z=[6],
                     mode='markers')
    )