Registry / data / palettable

palettable

JSON →
library3.3.3pypypi✓ verified 21d ago

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.

pip install palettable
INSTALL
IMPORT
SIG · PALETTABLE
P
palettable
datapythonv3.3.3
Install
2.0s avg
Import
580ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.3.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.600s · 21.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.0s · import 0.560s · 22MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Dark2_7
from palettable.colorbrewer.qualitative import Dark2_7
import brewer2mpl
The library was renamed from `brewer2mpl` to `palettable` in version 2.0.0.
Viridis_256
from palettable.matplotlib import Viridis_256
Palettes are imported directly by their name and number of colors from specific submodules (e.g., `colorbrewer.qualitative`, `matplotlib`).

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.")
Debug
Known issues
breakingThe library was renamed from `brewer2mpl` to `palettable` in version 2.0.0 (released March 2015). Code using `import brewer2mpl` will fail.
fix
Update imports to `from palettable.<source>.<type> import <PaletteName>_<NumColors>`.
affects: <2.0.0
gotchaPalettes are organized into submodules (e.g., `palettable.colorbrewer.qualitative`, `palettable.matplotlib`) and follow a naming convention of `<Name>_<number of colors>` (e.g., `Dark2_7`). Reversed palettes have an `_r` suffix.
fix
Refer to the documentation or use tab-completion to find the exact palette names and their available color counts.
affects: All versions
gotchaWhile Palettable itself has no external *core* dependencies, certain visualization and display functions (e.g., `show_as_blocks`, `show_discrete_image`, `save_continuous_image`) require `ipythonblocks` or `matplotlib` to be installed separately.
fix
Install `matplotlib` (for colormaps and image saving) or `ipythonblocks` (for IPython block displays) if you intend to use these specific features (`pip install matplotlib ipythonblocks`).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'palettable'
The `palettable` library is either not installed in your Python environment, or you are trying to import it using the old library name `brewer2mpl` after it was renamed to `palettable` in version 2.0.0.
fix
Ensure the library is installed with `pip install palettable`. If upgrading from `brewer2mpl`, update your import statements from `import brewer2mpl` to `import palettable` or `from palettable.<source>.<type> import <PaletteName>_<NumColors>`.
AttributeError: module 'palettable' has no attribute 'Dark2_7'
Color palettes within `palettable` are organized into specific submodules (e.g., `palettable.colorbrewer.qualitative`, `palettable.matplotlib`) and cannot be accessed directly from the top-level `palettable` module.
fix
Import the desired palette from its specific submodule, for example: `from palettable.colorbrewer.qualitative import Dark2_7`.
TypeError: 'LinearSegmentedColormap' object is not iterable
This error often occurs when attempting to use the `palette.mpl_colormap` attribute, which returns a continuous Matplotlib `LinearSegmentedColormap` object, with functions (especially in libraries like Seaborn) that expect an iterable of discrete colors (e.g., a list of RGB tuples or hex codes).
fix
If a list of RGB tuples (0-1 range) is needed, use `palette.mpl_colors`. For hex strings, use `palette.hex_colors`. If a discrete Matplotlib colormap is required, it can be created using `matplotlib.colors.ListedColormap(palette.mpl_colors)`.
ModuleNotFoundError: No module named 'matplotlib' (when using display functions)
While `palettable` has no external *core* dependencies, certain visualization and display functions (e.g., `show_as_blocks`, `show_discrete_image`, `save_continuous_image`) explicitly require `ipythonblocks` or `matplotlib` to be installed separately.
fix
Install the necessary visualization dependency: `pip install matplotlib` (for colormaps and image saving) or `pip install ipythonblocks` (for IPython block displays).
ImportError: cannot import name 'Blues_9' from 'palettable'
Specific palettes like 'Blues_9' are not directly available from the top-level 'palettable' module; they reside in submodules like 'palettable.colorbrewer.sequential'.
fix
from palettable.colorbrewer.sequential import Blues_9
Upgrade
Version history
3.3.3latest on PyPI · released Apr 19, 2023
Audit
Dependencies
matplotliboptionalRequired for generating matplotlib colormaps and for visualization functions like `show_discrete_image` or `save_continuous_image`.
ipythonblocksoptionalRequired for `show_as_blocks` function in IPython Notebooks.
Agent activity
6 hits · last 30 days
node
4
Resources