简单地说,给定初始颜色“#1010CA”和 alpha 因子 0.5,我如何才能根据 color="#1010CA", alpha=0.5
获得绘图上显示的最终颜色? ?
或者更直白一点,我应该填写什么
plot(x, y, color=__)
因此它等同于(至少在视觉上)
plot(x, y, color="#1010CA", alpha=0.5)
?我想这不应该是一个 python 问题,而是如何通过某种因素操纵 rgb 颜色来抑制它,但请原谅我对调色板的无知......
编辑
这是我在接受@Blender 的回答后选择的当前解决方案
import matplotlib
import numpy as np
def alpha_blending(hex_color, alpha) :
""" alpha blending as if on the white background.
"""
foreground_tuple = matplotlib.colors.hex2color(hex_color)
foreground_arr = np.array(foreground_tuple)
final = tuple( (1. - alpha) + foreground_arr*alpha )
return(final)
最佳答案
如果没有背景颜色,您也无法获得“最终颜色”。
但是为了渲染 alpha 透明度,我猜测加权和会起作用:
final = (1 - alpha) * background + alpha * foreground
所以如果你的颜色是白色并且你的alpha = 0.5
,你可以这样做:
final = rgb(0.5, 0.5, 0.5) + foreground / 2
Matplotlib 接受 RGB 元组,因此您可以非常轻松地制作不透明度展平函数。但是,我无法回答您为什么需要这样做。
关于python - 从 "alpha blending"获取一个新的十六进制颜色值 matplotlib 中的原始颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10646963/