python plotly colorbar for opacity

91 views Asked by At

I have a figure with multiple traces in it with different opacity and same color(green). The lines in my plot are overlapping, therefore I need some opacity of the lines, which than indicates another level of data. Now I want to add a colorbar, which goes from low opacity green to high opacity green. And I want to configure the labels to be words, for example high & low.

fig = go.Figure()
for i in list:
    fig.add_trace(go.Scatter(x=df.loc[i]['x'], y=df.loc[i]['y'], name=i,
                   line=dict(color='forestgreen', width=2), opacity=df_Transparency.loc[i][0]))
fig.show()

Everything I found only works for only the color or for matplotlib. "python matplotlib legend for opacity" is an example is how it is done in matplotlib.

I want something similar like this: I want something similar like this.]

And I tried with marker dict, but doesn't work as well.

marker=dict(
        size=5,
        color='forestgreen',
        colorbar=dict(
            title="Colorbar"
        ),
    )

Does someone know if it is possible to do it and how?

2

There are 2 answers

2
AudioBubble On

I guess you can use

colorscale=["rgb(0,255,0)","rgb(255,255,0)"]

colorscale=colorscale,
0
Lourenço Monteiro Rodrigues On

You can define the colorscale colors with 'rgba(red, green, blue, opacity)' so, for you case:

colorscale=['rgba(0, 255, 0, 0.0)', 'rgba(0, 255, 0, 1.0)']

which corresponds to going from full transparent to full opaque green.