如何将数据(或单点)添加到 python 中的现有 3d 散点图

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

我有一个代码可以制作与此类似的情节:

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()

我想添加一个具有不同符号的单个点,并在其余点中查看它

我试过了

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

并给了我: TypeError: 'module' object is not callable

可以吗? 这就是我要找的: enter image description here

问题是您的代码中有错字。您使用 go.scatter3d 而不是 go.Scatter3d

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