Is it possible to add an opacity to a color if you’re using a css color? Tried doing this
self.fig = go.Figure(data=[go.Sankey(
node=dict(
pad=15,
thickness=20,
line=dict(color="black", width=0.5),
label=self.label,
color=self.colors['node']
),
link=dict(
source=self.source,
target=self.target,
value=self.value,
color=[[color, .7] for color in self.colors['link']] # self.colors is a list of css colors
))])
but it doesn’t work and there’s no way to set an opacity flag. Any help would be appreicated.
It looks like you’re on the right track but the list comprehension you perform ([color, .7] for color in self.colors['link']) does not result in a list that is in the format that the plotly.py API expects.
If you can share the result of the list comprehension it would be helpful in further debugging your issue.
To translate css color names to rgba programmatically, you can use the matplotlib.colors module, which has a function called to_rgba() which accepts a named color and returns an rgba value.
This is an excellent solution for me as I was reading in a hex code from a custom template and wanted to apply opacity.
I created a global variable for the script which stored a computed f-string of the rgba value of the hex code, and then referenced that variable for the traces which required it.