Is there a function to return all single letter colors in Matplotlib?

Question:

I learnt of matplotlib.pyplot.colors that the basic built-in colors can be represented as a single letter.

  • b: blue
  • g: green
  • r: red
  • c: cyan
  • m: magenta
  • y: yellow
  • k: black
  • w: white

Is there a function in Matplotlib to return those colors?

Asked By: SparkAndShine

||

Answers:

The built in colors are available via matplotlib.colors.ColorConverter.colors

>>> print(matplotlib.colors.ColorConverter.colors)
{u'b': (0.0, 0.0, 1.0),
 u'c': (0.0, 0.75, 0.75),
 u'g': (0.0, 0.5, 0.0),
 u'k': (0.0, 0.0, 0.0),
 u'm': (0.75, 0, 0.75),
 u'r': (1.0, 0.0, 0.0),
 u'w': (1.0, 1.0, 1.0),
 u'y': (0.75, 0.75, 0)}
Answered By: Andy

It seems that the @Andy’s answer returns all available colors with varying color names.

You can use the following to get single color letters only:

 >>> [x for x in matplotlib.colors.ColorConverter.colors.keys() if len(x)==1]
Answered By: yosemite_k
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.