Get hex from matplotlib color name

I know this list of colors that matplotlib supports:

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

Is there a programmatic way to convert these names to hex?

I need a function that gets the name of a color and returns the hexadecimal value of that color.

Thank.

+4
source share
1 answer

matplotlib.colors.cnames - a dictionary of all matplotlib colors and their hexadecimal values:

import matplotlib
print matplotlib.colors.cnames["blue"]
  --> u'#0000FF'
+6
source

All Articles