List all Python colors available in Matplotlib?

What python colors are available for use in matplotlib plots?

I’ve come across the following list of color names in the matplotlib documentation, which claims that these are the only valid named colors:

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

However, I have found that I can also use other colors, such as:

  • scatter(X,Y, color=‘red’)
  • scatter(X,Y, color=‘orange’)
  • scatter(X,Y, color=‘darkgreen’)

These colors don’t appear in the original list. Can anyone provide an exhaustive list of python colors available in matplotlib?

Hello @smrity.maharishsarin

Matplotlib offers a great feature: named colors! You can use its extensive list of named colors directly. For example, you can access these colors like this:

import matplotlib.colors as mcolors  
print(mcolors.CSS4_COLORS)  

This gives you a dictionary of over 140 named colors, ranging from simple ones like ‘red’ and ‘blue’ to more specific ones like ‘cornflowerblue’ and ‘darkgoldenrod.’ It’s a handy way to use predefined python colors without needing to know their RGB values!

Hey All! Hope you all are doing Great!

That’s a solid starting point, @babitakumari ! Adding to your point, did you know that Matplotlib also supports XKCD colors? These come from the popular XKCD color survey and offer more than 950 unique color names. You can access them like this:*

import matplotlib.pyplot as plt  
print(plt.colors.XKCD_COLORS)  

This list includes quirky names like ‘vomit green’ or ‘cloudy blue’—great if you want a more informal or playful touch in your visualizations. It’s another excellent way to expand your palette of python colors!

Both named colors and XKCD colors are great resources! But if you want even more control, why not define your own colors? Matplotlib lets you use custom colors by specifying RGB or RGBA values directly. Here’s an example:

plt.scatter(X, Y, color=(0.5, 0.5, 0.5))  # This creates a gray scatter plot  

You can create any color by mixing red, green, and blue (plus alpha for transparency). This gives you infinite possibilities, ensuring your visualizations are as unique as you want them to be!