Scatter3d background plot color

Hi everyone! I want to change Scatter3D plot color but it seems plot_bgcolor doesnโ€™t work

Am I doing something wrong, or is there any workaround you can suggest to help me, fix this? Any help is highly appreciated.

import plotly.offline as ply
import plotly.graph_objects as go

x, y, z = np.random.normal(0, 1, 10000), np.random.normal(0, 1, 10000), np.random.normal(0, 1, 10000)
fig = go.Figure()
fig.add_trace(go.Scatter3d(x=x, y=y, z=z,
                                mode='markers',
                                marker=dict(size=1, color='olive'),
                                name='X-Y-Z distribution',
                                )
                   )
fig.add_trace(go.Scatter3d(x=x, y=y, z=np.ones(len(z)) * z.min() * 2,
                                mode='markers',
                                marker=dict(size=1, color='red'),
                                name='X-Y distribution',
                                hovertemplate='x:%{x:.2f}' +
                                              '<br>y:%{y:.2f}<br>'
                                )
                   )
fig.add_trace(go.Scatter3d(x=np.ones(len(x)) * x.min() * 2, y=y, z=z,
                                mode='markers',
                                marker=dict(size=1, color='green'),
                                name='Y-Z distribution',
                                hovertemplate='y:%{y:.2f}' +
                                              '<br>z:%{z:.2f}<br>'
                                )
                   )
fig.add_trace(go.Scatter3d(x=x, y=np.ones(len(y)) * min(y) * 2, z=z,
                                mode='markers',
                                marker=dict(size=1, color='blue'),
                                name='X-Z distribution',
                                hovertemplate='x:%{x:.2f}' +
                                              '<br>z:%{z:.2f}<br>'
                                )
                   )
fig.update_layout(scene=dict(xaxis=dict(range=[-10, 10], showgrid=True, gridwidth=1, gridcolor='LightPink'),
                                     yaxis=dict(range=[-10, 10]),
                                     zaxis=dict(range=[-10, 10])),
                          plot_bgcolor='rgb(12,163,135)',
                         )
ply.plot(fig)

Hi @Severitatem, you have to use the bgcolor attribute of scene for this, for example

fig.update_layout(scene=dict(
                                     xaxis=dict(range=[-10, 10], showgrid=True, gridwidth=1, gridcolor='LightPink'),
                                     yaxis=dict(range=[-10, 10]),
                                     zaxis=dict(range=[-10, 10]),
                                     bgcolor='cyan'
),
                             plot_bgcolor='rgb(12,163,135)',
                         )
fig.show()
1 Like

Hi @Emmanuelle

Let me know how to remove the gray background color that we can see in above plot? I mean the color of background the is between grid lines?

Hi again @Emmanuelle and @Severitatem

My problem solved. I put the code that solved my problem, maybe become helpful for someone else:

    fig.update_layout(#plot_bgcolor='rgb(12,163,135)',
                      #paper_bgcolor='rgb(12,163,135)'
                      #coloraxis={"colorbar": {"x": -0.2, "len": 0.5, "y": 0.8}}, #I think this is for contours
                     scene = dict(
                                    xaxis = dict(
                                         backgroundcolor="rgba(0, 0, 0,0)",
                                         gridcolor="white",
                                         showbackground=True,
                                         zerolinecolor="white",),
                                    yaxis = dict(
                                        backgroundcolor="rgba(0, 0, 0,0)",
                                        gridcolor="white",
                                        showbackground=True,
                                        zerolinecolor="white"),
                                    zaxis = dict(
                                        backgroundcolor="rgba(0, 0, 0,0)",
                                        gridcolor="white",
                                        showbackground=True,
                                        zerolinecolor="white",),),
                     )

Thank you for this ! It really helped me!

1 Like