Colourmap
The `colourmap` Python package, currently at version 1.2.1, generates N unique colors from a specified input colormap or list of colors. It also provides utilities for converting between RGB and HEX color formats and can create linear gradients. The package appears to have a moderate release cadence, with recent updates in late 2025.
Common errors
-
ModuleNotFoundError: No module named 'colormap'
cause Attempted to import 'colormap' (without 'u') when the installed package is 'colourmap' (with 'u').fixChange your import statement to `from colourmap import colourmap`. -
TypeError: generate_unique_colors() got an unexpected keyword argument 'cmap_name'
cause You are trying to specify a colormap by name directly with a 'cmap_name' argument, which is not supported by this library's `generate_unique_colors` function. It implicitly uses an internal colormap or expects `input_colors`.fixIf you want to use a specific colormap (e.g., from matplotlib or seaborn), first generate a list of colors from that colormap using its respective library, and then pass that list to `colourmap.generate_unique_colors` via the `input_colors` parameter.
Warnings
- gotcha There are multiple Python packages with similar names ('colormap', 'cmap', 'colormaps'). Ensure you are installing and importing 'colourmap' (with 'u') if you intend to use this specific library.
- gotcha The `generate_unique_colors` function can take either `n_colors` (to generate from an internal colormap) or `input_colors` (to sample from a provided list). Using both might lead to unexpected behavior or an error depending on the implementation details for argument precedence.
Install
-
pip install colourmap
Imports
- colourmap
from colourmap import colourmap
Quickstart
from colourmap import colourmap
# Generate 5 unique colors from a default colormap
colors_hex = colourmap.generate_unique_colors(n_colors=5)
print(f"Generated HEX colors: {colors_hex}")
# Generate 3 unique colors from a specified list of input colors (e.g., using a seaborn palette)
# For demonstration, we'll use a simple list; in a real scenario, this might come from seaborn.color_palette
input_palette = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b']
colors_from_palette_hex = colourmap.generate_unique_colors(input_colors=input_palette, n_colors=3)
print(f"Generated HEX colors from palette: {colors_from_palette_hex}")
# Convert RGB to HEX
rgb_color = (255, 0, 0)
hex_color = colourmap.rgb_to_hex(rgb_color)
print(f"RGB {rgb_color} to HEX: {hex_color}")
# Convert HEX to RGB
hex_color_input = '#00FF00'
rgb_color_output = colourmap.hex_to_rgb(hex_color_input)
print(f"HEX {hex_color_input} to RGB: {rgb_color_output}")