mkt.databases.colors.generate_colormap_legend

mkt.databases.colors.generate_colormap_legend(color_stops: dict[int, tuple[str, str]], output_path: str | None = None, zero_color: str = 'darkgray', n_gradient_steps: int = 256, null_steps: int | None = None, figsize: tuple[float, float] = (0.75, 5.5)) None[source]

Generate a vertical colormap legend image (SVG and PNG) from color stops.

Creates a vertical gradient bar from bottom (null/zero color) to top (highest density), with percentile tick labels at 0, 0.25, 0.5, 0.75, and 1. Colors are generated via percentile_colormap with a synthetic uniform dataset so the legend is guaranteed to match live usage.

Parameters:

color_stopsdict[int, tuple[str, str]]

Dict mapping bin number (1-indexed) to (start_hex, end_hex) tuples, e.g., DICT_QUARTILE_HEATMAP_COLORMAP.

output_pathstr | None

Directory path to save the plot. If None, saves to the repo root.

zero_colorstr

Color for the null/zero band at the bottom (default: DEFAULT_NULL_COLOR).

n_gradient_stepsint

Number of interpolation steps per bin (default: 256).

null_stepsint | None

Height in pixels of the null/zero color band at the bottom. Defaults to 1/10 the height of one bin (n_gradient_steps // 10).

figsizetuple[float, float]

Figure size in inches (width, height). Default: (1, 5).