从颜色名称matplotlib获取十六进制

Ore*_*ren 4 python hex colors matplotlib

我知道matplotlib支持的这个颜色列表:

https://pythonhosted.org/ete2/reference/reference_svgcolors.html

有没有一种程序化的方法将这个名称转换为十六进制?

我想要一个接收颜色名称并返回此颜色的十六进制值的函数.

谢谢.

Car*_*ten 6

matplotlib.colors.cnames 是matplotlib所有颜色及其十六进制值的字典:

import matplotlib
print matplotlib.colors.cnames["blue"]
  --> u'#0000FF'
Run Code Online (Sandbox Code Playgroud)