Black Lives Matter. Please consider donating to Black Girls Code today.

How can I change the opacity of specific scatterplot dots (markers)?

I have a plotly figure containing several scatterplot traces. For every scatterplot trace I’d like to change the opacity of every specific marker according to the input data. The input data for every dot opacity is a value between 0 and 1 which could be directly mapped to opacity. (I am thinking of something similar as the color coding in a heatmap.) How can I achieve this?

Seem like scatter-marker-opacity reference is what I was looking for. Specifying an array with trace marker specific opacities should do the job.

@fcromer You cannot define a list (array) of opacities, because opacity attribute has a unique value for each trace. Instead you can define the marker colors as a list of rgba color codes, one for each marker.

fig = go.Figure(go.Scatter(x =[1,2,3], y=[-2, 5, 4], mode='markers', 
                         marker_color=['rgba(255,0,255, 0.4)', 'rgba(255,127,80, 0.25)', 
                                                                   'rgba(60,179,113, 0.7)']), 
                layout_width=600, layout_height=300)


I’m modifying the markers opacity, not the one of the trace and it works perfectly fine for me:

data_scaled_to_values_between_0_and_1 = [...]

trace = go.Scattergl(
1 Like

Nice. Perhaps this a newer property because before I knew that opacity can be just a number in [0,1].

1 Like