brewer2mpl

1.4.1 · deprecated · verified Thu Apr 16

brewer2mpl is a Python package that provides access to the ColorBrewer2.org color maps. It allows users to retrieve sequential, diverging, and qualitative color palettes in various formats, including RGB 0-255, hex strings, and 0-1 normalized RGB triplets suitable for Matplotlib. The library is no longer actively maintained; its functionality has been superseded by the `Palettable` library. The current version is 1.4.1, released in 2014, and there are no further updates planned.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to fetch a named qualitative color map, access its Matplotlib-compatible RGB colors (0-1 range), and print relevant information. The commented-out Matplotlib plotting code shows a simple way to visualize the retrieved colors.

import brewer2mpl
import matplotlib.pyplot as plt

# Get a qualitative color map named 'Set2' with 7 colors
bmap = brewer2mpl.get_map('Set2', 'Qualitative', 7)

# Access colors as 0-1 RGB triplets for Matplotlib
colors_for_mpl = bmap.mpl_colors

print(f"Color map name: {bmap.name}")
print(f"Number of colors: {bmap.number}")
print(f"Matplotlib compatible colors (0-1 RGB): {colors_for_mpl}")

# Example of using colors in a Matplotlib plot (if matplotlib is installed)
# plt.figure(figsize=(7, 1))
# for i, color in enumerate(colors_for_mpl):
#     plt.barh(0, 1, left=i, color=color)
# plt.axis('off')
# plt.title('Brewer2mpl Set2 Qualitative (7 colors)')
# plt.show()

view raw JSON →