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

**URL:** <https://community.plotly.com/t/how-can-i-change-the-opacity-of-specific-scatterplot-dots-markers/31306>\
**Category:** 📊 Plotly Python\
**Created:** [November 14, 2019, 8:07am UTC](https://community.plotly.com/t/how-can-i-change-the-opacity-of-specific-scatterplot-dots-markers/31306 "2019-11-14T08:07:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fkromer](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@fkromer](https://community.plotly.com/u/fkromer)\
**Post date:** [November 14, 2019, 8:07am UTC](https://community.plotly.com/t/how-can-i-change-the-opacity-of-specific-scatterplot-dots-markers/31306/1 "2019-11-14T08:07:57Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![fkromer](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@fkromer](https://community.plotly.com/u/fkromer)\
**Post date:** [November 14, 2019, 9:43am UTC](https://community.plotly.com/t/how-can-i-change-the-opacity-of-specific-scatterplot-dots-markers/31306/2 "2019-11-14T09:43:41Z")

</div>

Seem like [scatter-marker-opacity](https://plot.ly/python/reference/#scatter-marker-opacity) reference is what I was looking for. Specifying an array with trace marker specific opacities should do the job.

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [November 14, 2019, 12:51pm UTC](https://community.plotly.com/t/how-can-i-change-the-opacity-of-specific-scatterplot-dots-markers/31306/3 "2019-11-14T12:51:03Z")

</div>

@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.

```auto
fig = go.Figure(go.Scatter(x =[1,2,3], y=[-2, 5, 4], mode='markers', 
                         marker_size=25,
                         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)

```

![marker-opacity](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/f/fbab566b2c9182fdc9c8a7c34e57bdde64d25290.png)

---

<div class="post-metadata">

**Author:** ![fkromer](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@fkromer](https://community.plotly.com/u/fkromer)\
**Post date:** [November 14, 2019, 1:00pm UTC](https://community.plotly.com/t/how-can-i-change-the-opacity-of-specific-scatterplot-dots-markers/31306/4 "2019-11-14T13:00:18Z")

</div>

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

```auto
data_scaled_to_values_between_0_and_1 = [...]

trace = go.Scattergl(
    x=mz_values,
    y=idx_values,
    mode='markers',
    marker=dict(opacity=data_scaled_to_values_between_0_and_1),
)

```

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [November 14, 2019, 1:44pm UTC](https://community.plotly.com/t/how-can-i-change-the-opacity-of-specific-scatterplot-dots-markers/31306/5 "2019-11-14T13:44:48Z")

</div>

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