Matplotlib颜色输入功能?

问题描述 投票:0回答:1

是否可以通过color=传递函数:

plt.plot(x, y, 'o', color= color_converter)

该函数接收255中的RGB值,并将其转换为0-1比例的RGB值。这是函数:

coordinate = myImage[350, 350]
def color_converter(rgb):
    conversion_forumla = rgb/255
    rgb_to_hex = colors.rgb2hex(conversion_forumla)
    return rgb_to_hex
color_converter(coordinate)

我想传递一个在color=中以0-1比例返回RBG值的函数,但出现此错误:

ValueError: Invalid RGBA argument: <function color_converter at 0x10885d160>
python function matplotlib plot rgb
1个回答
0
投票

在matplotlib中,颜色转换器是以下形式的值元组:([0-1],[0-1],[0-1]),例如(0.1,0.5,0.3)

我没有代码的全貌,但似乎您计算的是0到1之间的一个值,而不是元组?

rgb = (0.5, 0.2, 0.1) # for instance
new_rgb = tuple([e/255 for e in rgb])

然后将新的rgb传递给绘图功能

© www.soinside.com 2019 - 2024. All rights reserved.