In plotly how to define colour and marker when adding a 3D trace?

41 Views Asked by At

I am running successfully the following plotly code to create a 3D plot:

import plotly.express as px
import plotly.graph_objs as go

fig = px.scatter_3d(df, x='x', y='y', z='z')

What I want to do next is to add more data points to the 3D plot AND define the marker shape (e.g. as squares) as well as define the color. So I did the following

fig.add_trace(go.Scatter3d(x=df2["x"], y=df2["y"], z=df2['z'], mode='markers', color='black', markers='s'))

but this leads to error messages, since color and markers are not accepted keywords. Unfortunately, the documentation about this is very short and not comprehensible for me. I also wonder if I am confusing the functionalities of go.Scatter3d and go.scatter3d, since both are actual code with different functionalities. So what code should I do to define myself the colour and marker shapes for added points? Thx

1

There are 1 best solutions below

0
NeStack On

I asked eventually ChatGPT and it gave me the correct answer, this is what I need to use:

fig.add_trace(go.Scatter3d(x=df2["x"], y=df2["y"], z=df2['z'], mode='markers', marker=dict(color='black', symbol='square')))