Colorlover: Color Scales for Python
Colorlover is a Python library providing a collection of qualitative, sequential, and diverging color scales, originally designed for use with IPython notebooks. It offers utilities for converting between RGB and HSL color formats, generating numeric representations, and outputting scales as HTML. The library's current version is 0.3.0, released in January 2019, and it appears to be in a maintenance state with no recent active development.
Common errors
-
ImportError: No module named 'colorlover'
cause The `colorlover` package is not installed or the Python environment where it was installed is not the one being used.fixEnsure the package is installed in your active environment: `pip install colorlover`. -
AttributeError: module 'colorlover' has no attribute 'some_api_method'
cause This error often occurs when users confuse `colorlover` (static scales) with `python-colourlovers` (COLOURlovers API client) and attempt to call methods like `cl.palettes()` or `cl.colors()` to fetch data from the internet.fixThe `colorlover` library provides color scales through `cl.scales` directly, e.g., `cl.scales['3']['div']['RdYlBu']`. It does not make API calls. If you need to interact with the COLOURlovers API, you need a different library or custom API calls.
Warnings
- gotcha The `colorlover` library has not seen significant updates since its 0.3.0 release in January 2019. While it remains functional for its core purpose, users should be aware of its age and potential lack of support for newer Python features or modern ecosystem integrations.
- gotcha The project's description mentions 'IPython notebook', a term largely superseded by 'Jupyter notebook' and 'JupyterLab'. This indicates the library's historical context and might not align with current best practices in the broader Python data science ecosystem.
- gotcha Users often confuse `colorlover` with `python-colourlovers` (or `colourlovers`), a different library that acts as a client for the `COLOURlovers.com` API. `colorlover` (this library) provides static, built-in color scales and *does not* interact with the `COLOURlovers.com` API.
Install
-
pip install colorlover
Imports
- cl
import colorlover as cl
Quickstart
import colorlover as cl
# Access a diverging color scale with 3 colors
scale_rgb_str = cl.scales['3']['div']['RdYlBu']
print(f"RGB string scale: {scale_rgb_str}")
# Convert to numeric RGB tuples
scale_numeric_rgb = cl.to_numeric(scale_rgb_str)
print(f"Numeric RGB scale: {scale_numeric_rgb}")
# Convert to HSL strings
scale_hsl_str = cl.to_hsl(scale_rgb_str)
print(f"HSL string scale: {scale_hsl_str}")