Plotly python fill - control opacity of filled area?

Is there a way to control how opaque the filled area between y is between two traces? I have tried adjusting opacity in the trace attributes as well as marker attributes and neither works. Default via the reference (https://plot.ly/python/reference/#scatter-fill) is half transparent of whatever color the marker is set to. So I can only get it to be fully opaque (if I manually set the color of the fill with โ€˜fillcolor=โ€™) or half opaque if I do nothing.

Specify an alpha value via fillcolor, like so:
fillcolor=โ€˜rgba(255, 0, 0, 0.1)โ€™,

This would be a fairly transparent red.

5 Likes

Nice - did not think of that. Does the trick. Thanks.

1 Like

This does not seem to work anymore:

import plotly
import plotly.graph_objs as go
plotly.io.renderers.default = "browser"


fig = go.Figure()


fig.add_trace(go.Scatter(
    x=[0., 1., 2.], y=[1., 1., 2.],
    line={"color": "rgb(99, 110, 250)", "width": 1., "dash": "dash"},
))

fig.add_trace(go.Scatter(
    x=[0., 1., 2.], y=[3., 2., 3.],
    line={"color": "rgb(99, 110, 250)", "width": 1., "dash": "dash"},
                                 fill='tonexty', fillcolor="rgb(99, 110, 250, .1)",
))

fig.add_trace(go.Scatter(
    x=[0., 1., 2.], y=[1.5, 1.5, 2.5],
    line={"color": "rgb(99, 110, 250)", "width": 1., "dash": "dash"},
))


fig.show()

The filled area is not transparent:

Hey @lukas_hbng, yes it does, you forgot the โ€œaโ€ in the rgba- string.

2 Likes

That works, thanks!