据我对Plotly的有限了解,它以"rgb(23, 57, 211)"
或"rgba(23, 57, 211, 0.5)"
之类的字符串表示颜色,但是我找不到从RGB转换为RGBA的函数。我需要此功能,因为我想向DEFAULT_PLOTLY_COLORS"
中定义的colors.py
中的RGB颜色添加Alpha通道。我知道这是非常简单的字符串操作,我可以编写自己的函数,但是有官方的Plotly函数来执行此操作吗?
答案 0 :(得分:1)
截至今天,据我所知,不存在此类功能。对于任何寻找解决方案的人来说,这对我来说很好
def rgb_to_rgba(rgb_value, alpha):
"""
Adds the alpha channel to an RGB Value and returns it as an RGBA Value
:param rgb_value: Input RGB Value
:param alpha: Alpha Value to add in range [0,1]
:return: RGBA Value
"""
return f"rgba{rgb_value[3:-1]}, {alpha})"