Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:DistrictDataLabs Yellowbrick Drawing Utilities

From Leeroopedia


Knowledge Sources
Domains Visualization, Utilities
Last Updated 2026-02-08 05:00 GMT

Overview

Utility functions for common matplotlib drawing procedures including manual legends and stacked bar charts, provided by the Yellowbrick library.

Description

The draw module provides manual_legend for adding custom legends with colored circle patches to scatter plots, and bar_stack for rendering stacked bar charts with customizable orientation, colors, and legends. These are used internally by multiple Yellowbrick visualizers.

Usage

Import these utilities when building custom visualizations that need manual legend construction or stacked bar chart rendering.

Code Reference

Source Location

Signature

def manual_legend(g, labels, colors, **legend_kwargs):
    """Adds a manual legend with colored circle patches."""

def bar_stack(data, ax=None, labels=None, ticks=None, colors=None,
              colormap=None, orientation="vertical", legend=True,
              legend_kws=None, **kwargs):
    """Creates a stacked bar chart."""

Import

from yellowbrick.draw import manual_legend, bar_stack

I/O Contract

Inputs (manual_legend)

Name Type Required Description
g Visualizer or Axes Yes Target for legend
labels list of str Yes Legend labels
colors list Yes Colors for each label

Inputs (bar_stack)

Name Type Required Description
data 2D array-like Yes Data for stacked bars
ax matplotlib.Axes No Target axes
labels list of str No Stack segment labels
orientation str No "vertical" or "horizontal" (default: "vertical")

Outputs

Name Type Description
ax matplotlib.Axes Axes with rendered elements

Usage Examples

import matplotlib.pyplot as plt
from yellowbrick.draw import manual_legend, bar_stack
import numpy as np

# Stacked bar chart
data = np.random.randint(1, 10, size=(3, 5))
fig, ax = plt.subplots()
bar_stack(data, ax=ax, labels=["A", "B", "C"], ticks=["G1", "G2", "G3", "G4", "G5"])
plt.show()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment