python - Plotly函数将RGB颜色转换为RGBA?(Python)
问题描述
就我对 Plotly 的有限了解而言,它将颜色表示为"rgb(23, 57, 211)"
, 或之类的字符串"rgba(23, 57, 211, 0.5)"
,但我找不到从 RGB 转换为 RGBA 的函数。我想要这个函数,因为我想将 alpha 通道添加DEFAULT_PLOTLY_COLORS"
到colors.py
. 我知道这是非常简单的字符串操作,我可以编写自己的函数,但是有官方的 Plotly 函数可以做到这一点吗?
解决方案
截至今天,据我所知,不存在这样的功能。对于任何寻找解决方案的人来说,这对我来说都很好
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})"
推荐阅读
- php - 按产品选项值过滤产品(Mysql 查询)
- python - 通过二进制文件生成很多curl命令
- azure - 如何创建一个体系结构,让多个资源组在 Azure 上共享一个数据库服务器?
- java - Java中的HTTP Get Response解析并存储在字符串中
- postgresql - 将数据导入 Prisma / PostgreSQL 服务的最有效方法?
- ios - 快速滚动 UIPageViewController 阻止 viewcontroller 更新
- tensorflow - 如何使用 TensorFlow 的 `tf.data` API 多次获取相同的数据批次
- c# - 如何在 C# XAML WPF 中处理数据修改
- python - on_voice_state_update() 接受 2 个位置参数,但给出了 3 个
- python - 如何错开异步 API 调用以防止使用 grequests 库进行最大重试?