Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Python从颜色名称到RGB_Python 3.x_Matplotlib_Colors_Rgba - Fatal编程技术网

Python 3.x Python从颜色名称到RGB

Python 3.x Python从颜色名称到RGB,python-3.x,matplotlib,colors,rgba,Python 3.x,Matplotlib,Colors,Rgba,如果我有一个函数,它将颜色作为输入,首先(通过RGB编号)进行编辑,然后在matplotlib.pyplot中使用。如何将颜色名称转换为RGB 例如: def function(color): color[3] = 0.5 plt.plot([1,2],[2,4], color = color) 然后函数((0,0,1,1))起作用,但是函数('blue')将只在plt.plt上起作用 如何将颜色名称转换为RGB(例如蓝色转换为(0,0,1,1)) 谢谢。您可以与matpl

如果我有一个
函数
,它将
颜色
作为输入,首先(通过RGB编号)进行编辑,然后在
matplotlib.pyplot
中使用。如何将颜色名称转换为RGB

例如:

def function(color):
     color[3] = 0.5
     plt.plot([1,2],[2,4], color = color)
然后
函数((0,0,1,1))
起作用,但是
函数('blue')
将只在
plt.plt上起作用

如何将颜色名称转换为RGB(例如
蓝色
转换为
(0,0,1,1)


谢谢。

您可以与
matplotlib.colors

from matplotlib import colors

print(colors.to_rgba('blue'))
结果:

(0.0, 0.0, 1.0, 1.0)
找到了解决方案

from matplotlib import colors
orange_rgb = colors.hex2color(colors.cnames['orange'])

如何从python中的rgb值中获取颜色名称?