How to define opacity per point for Scatter3D?

I would like to define the opacity per point for a Scatter3D plot. I’ve tried to do this by defining a rgba color per point, but the alpha component seems to be treated as white (example code below). Any suggestions? I found the following relevant stackoverflow questions ( one, two ) but no solutions were posted. Thanks!

import plotly
import plotly.graph_objs as go
import plotly.offline as off
import numpy as np

x_max = 2
num_bins = 20

linspace = np.linspace(-x_max, x_max, num_bins)
X, Y, Z = np.meshgrid(linspace, linspace, linspace)

gaussian = lambda x: np.exp(-np.sum(np.power(x, 2), 0, keepdims=False)/0.5)

coords = np.concatenate((np.expand_dims(X.flatten(), 0),
                         np.expand_dims(Y.flatten(), 0),
                         np.expand_dims(Z.flatten(), 0)), 0)

gaussian_coords = gaussian(coords)

color_scale = lambda x: 'rgba(255, 0, 0, {})'.format(np.round(x, 2))

half = int(20**3/2)

trace1 = go.Scatter3d(
        color = list(map(color_scale, 
        line=dict(width=0, color='rgba(0, 0, 0, 0)'),
        # opacity=0.5  # Toggle this to see the Gaussian shape more clearly


layout=go.Layout(height=600, width=600)

fig=go.Figure(data=data, layout=layout)

Hi @blondegeek,

I see what you mean. I think the best thing to do is to open an issue with the plotly.js project at Just include your example code and some screenshots of the odd behavior you’re seeing.


Hi @jmmease,
Thanks for the reply. As per your advice, I’ve opened the issue here.

Hi @blondegeek,

I responded to the issue with some info on the plotly.js issues that I opened as a result of your example.

As a side note, it looks like you’re trying to use scatter3d to do some form of 3d density rendering. You may be interested to keep an eye out for two new trace types that will be coming to

The first is isosurface, this one is already in plotly.js and will be released in 3.6 pretty soon. See the Plotly.js PR and examples at for more info.

The second is a true volume 3d trace type. See the in progress plotly.js PR at and demos at This won’t be in 3.6.0, but hopefully it won’t be too much longer after that.


Hi @jmmease,
I was indeed trying to approximate a 3D voxel image. Thanks for the head up on the upcoming trace types. Those will both be very useful to me.
Thank you again for your help!