Implementation:DistrictDataLabs Yellowbrick Color Utilities
| Knowledge Sources | |
|---|---|
| Domains | Visualization, Style |
| Last Updated | 2026-02-08 05:00 GMT |
Overview
Utility functions for resolving and managing colors from matplotlib's color cycle and Yellowbrick's color palettes.
Description
The style.colors module provides get_color_cycle to retrieve the current matplotlib color cycle and resolve_colors to generate a list of N colors from a colormap, explicit color list, or the default palette. resolve_colors handles truncation and cycling to match the requested count.
Usage
Import these utilities when building custom visualizers that need to resolve colors consistently with Yellowbrick's style system.
Code Reference
Source Location
- Repository: DistrictDataLabs_Yellowbrick
- File: yellowbrick/style/colors.py
- Lines: 1-205
Signature
def get_color_cycle():
"""Returns the current matplotlib color cycle."""
def resolve_colors(n_colors=None, colormap=None, colors=None):
"""Generates a list of colors from colormap, explicit list, or default palette."""
Import
from yellowbrick.style.colors import get_color_cycle, resolve_colors
I/O Contract
Inputs (resolve_colors)
| Name | Type | Required | Description |
|---|---|---|---|
| n_colors | int | No | Number of colors to return |
| colormap | str or Colormap | No | Named colormap to sample from |
| colors | list | No | Explicit color list to use |
Outputs
| Name | Type | Description |
|---|---|---|
| colors | list | List of resolved color values |
Usage Examples
from yellowbrick.style.colors import resolve_colors, get_color_cycle
# Get 5 colors from the default palette
colors = resolve_colors(n_colors=5)
# Get colors from a specific colormap
colors = resolve_colors(n_colors=8, colormap="viridis")
# Get current color cycle
cycle = get_color_cycle()