# Scatter plot fill with color - how to set opacity of fill?

Hi!
I have a graph with fill and fill color

{
‘x’: n.index, ‘y’: n,
‘type’: ‘scatter’, ‘name’: name, ‘legendgroup’: name,
‘mode’: ‘markers’, ‘fill’:‘tozeroy’, #‘fillcolor’:’#f0f0f0’, ‘opacity’:0.4,
‘marker’:{ ‘symbol’: ‘diamond’, ‘size’: 7, ‘color’: ‘#bf6f73’},
‘traceorder’:‘grouped’, ‘showlegend’: False,
‘barmode’: ‘overlay’, ‘offset’:’-2’,
}

Opacity does not work, I have a solid fill. How to solve it?
Tom

Hi,

you could either:

• Use `"rgba(red, green, blue, alpha)"`

• Or if you would rather keep your hex colors here is a small snippet I just wrote

``````def hex_to_rgb(hex_color: str) -> tuple:
hex_color = hex_color.lstrip("#")
if len(hex_color) == 3:
hex_color = hex_color * 2
return int(hex_color[0:2], 16), int(hex_color[2:4], 16), int(hex_color[4:6], 16)
``````

Then you may use

``````fillcolor=f"rgba{(*hex_to_rgb(hex_color), opacity)}"
``````
1 Like

Thanks a lot - it works prefectly !!

You need to double each single character so that
`#123` becomes `#112233`
youre doing: `#123123` instead

A proper way to calculate that is:

``````hex_color = ''.join(x + y for x, y in zip(hex_color , hex_color))
``````

My hex_to_rgba looks like this

``````def hex2rgba(x):
if len(x) < 6:
return tuple(17 * int(x[n+1], 16) * (1 if n < 3 else 1/255) for n in range(len(x) - 1))
else:
return tuple(int(x[2*n+1:2*n+3], 16) * (1 if n < 3 else 1/255) for n in range(len(x) // 2))
``````

where I also receive the opacity if it was part of the string