从颜色名称到RGB的Python [英] Python from color name to RGB

查看:331
本文介绍了从颜色名称到RGB的Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

If I have a function which takes color as an input to be edited first (by RGB numbers), and then used in matplotlib.pyplot. How can I convert color name to 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

then function((0,0,1,1)) works, but function('blue') will only work on the plt.plot.

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

How can I convert color name to RGB, (such as blue to (0,0,1,1))?

谢谢。

推荐答案

可以与 matplotlib.colors

from matplotlib import colors

print(colors.to_rgba('blue'))

结果:

(0.0, 0.0, 1.0, 1.0)

这篇关于从颜色名称到RGB的Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆