Available colors in Matplotlib

logo of a chart:Colours

A blogpost showing how to use use colors in Python and matplotlib.

This blogpost explains how to use hexadecimal color codes, pre-defined color names, RGB tuples, and RGBA tuples in matplotlib. The blogpost also shows the full list of available color names and short color names in matplotlib.

What Matplotlib interprets as a color

In matplotlib, you can specify colors in a variety of ways:

  • as a string representing a color name (e.g., red or blue), but only a limited number of colors are supported this way
  • as a string representing a hexadecimal color code (e.g., #FF0000 or #e9edc9), which allows you to specify any color
  • as a string representing an RGB or RGBA tuple (e.g., (1, 0, 0) or (0.9, 0.9, 0.8, 1)), which also allows you to specify any color. RGB stands for Red, Green, Blue, and RGBA stands for Red, Green, Blue, Alpha (the alpha channel specifies the transparency of the color).

Let's see how these different ways of specifying colors work in practice.

import matplotlib.pyplot as plt
import numpy as np

random_data = np.random.randn(1000)

# Create a figure and a set of 4 subplots
fig, axs = plt.subplots(nrows=2, ncols=2, figsize=(10, 10), dpi=200)

# Hexadecimal color codes
color = "#FF5733"
axs[0,0].hist(
    random_data,
    bins=30,
    density=True,
    color=color
)
axs[0,0].set_title(f"color = {color}")

# Pre-defined color names
color = "skyblue"
axs[0,1].hist(
    random_data,
    bins=30,
    density=True,
    color=color
)
axs[0,1].set_title(f"color = {color}")

# RGB tuple
color = (0.1, 0.2, 0.5)
axs[1,0].hist(
    random_data,
    bins=30,
    density=True,
    color=color
)
axs[1,0].set_title(f"color = {color}")

# RGBA tuple
color = (0.1, 0.2, 0.5, 0.4)
axs[1,1].hist(
    random_data,
    bins=30,
    density=True,
    color=color
)
axs[1,1].set_title(f"color = {color}")

plt.show()

Available color names

Matplotlib supports a limited number of color names. You can see the full list of supported color names below.

Color names

Short color names

Matplotlib also supports a few short color names. You can see the full list of supported short color names below.

Color names

Going further

Palette finder

Browse the color palette finder to find your dream palette!

Related

Animation with python

Animation

🚨 Grab the Data To Viz poster!


Do you know all the chart types? Do you know which one you should pick? I made a decision tree that answers those questions. You can download it for free!

    dataviz decision tree poster