如果我有一个function
,它接受color
作为输入,首先(通过RGB数字)进行编辑,然后在matplotlib.pyplot
中使用。如何将颜色名称转换为RGB?
例如:
def function(color):
color[3] = 0.5
plt.plot([1,2],[2,4], color = color)
那么function((0,0,1,1))
就可以工作了,但是function('blue')
只能在plt.plot
上工作。
如何将颜色名称转换为RGB (如blue
到(0,0,1,1)
)?
谢谢。
发布于 2018-07-16 02:59:40
可以与matplotlib.colors
一起使用
from matplotlib import colors
print(colors.to_rgba('blue'))
结果:
(0.0, 0.0, 1.0, 1.0)
发布于 2018-07-16 03:47:30
找到了解决方案,通过
from matplotlib import colors
orange_rgb = colors.hex2color(colors.cnames['orange'])
https://stackoverflow.com/questions/51350872
复制相似问题