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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.600s · 21.7MB
glibcpy 3.10–3.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.")
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.
fixEnsure 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.
fixImport 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).
fixIf 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.
fixInstall 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'.
fixfrom 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.