Palettable

3.3.3 · active · verified Sun Apr 12

Palettable is a Python library that provides a comprehensive collection of color palettes, including those from Colorbrewer2, Tableau, CartoColors, cmocean, and more. It is written in pure Python with no external dependencies and can supply color maps for Matplotlib or be used for web applications. The current version is 3.3.3, with an irregular release cadence and maintenance releases as needed.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import a specific color palette, access its various color representations (RGB 0-255, Hex, Matplotlib-compatible RGB 0-1), and optionally visualize it using Matplotlib.

from palettable.colorbrewer.qualitative import Dark2_7

# Access basic palette information
print(f"Palette Name: {Dark2_7.name}")
print(f"Number of Colors: {Dark2_7.number}")

# Get colors in different formats
print(f"RGB colors (0-255): {Dark2_7.colors}")
print(f"Hex colors: {Dark2_7.hex_colors}")
print(f"Matplotlib-compatible RGB (0-1): {Dark2_7.mpl_colors}")

# Example: Using with Matplotlib (requires matplotlib installed)
try:
    import matplotlib.pyplot as plt
    from matplotlib.colors import ListedColormap

    # Create a matplotlib colormap from the palette
    cmap = ListedColormap(Dark2_7.mpl_colors)

    # Display the palette as an image
    fig, ax = plt.subplots(figsize=(6, 1))
    ax.imshow([[i for i in range(Dark2_7.number)]], cmap=cmap, aspect='auto')
    ax.set_axis_off()
    ax.set_title(f"{Dark2_7.name} ({Dark2_7.number} colors)")
    plt.show()
except ImportError:
    print("Matplotlib not installed. Skipping visualization example.")

view raw JSON →