Subway signs

subway_signs() lays out labeled colored circles. It is a compact district key for maps and multi-panel reports, especially when a conventional legend would consume too much vertical space. Pass colors and labels in the same order used by the plan map.

import matplotlib.pyplot as plt

from gerrytools.colors import districtr
from gerrytools.plotting import subway_signs

labels = [str(district) for district in range(1, 15)]
colors = districtr(len(labels))

subway_signs(colors, labels)
plt.show()
../../../../_images/3f3eb893cdba6ed9e5086f889da21777fc1d44231ac2fc0ce2c88498315c1297.png

The function returns the (Figure, Axes) pair it draws. Pass ax= to reserve a panel for the key in an existing Matplotlib layout, or filepath= to save it directly. The function does not infer district labels from a map, so the ordering of the two input sequences is the complete color-to-label contract.

Layout

The default is one horizontal band. orientation= changes the reading direction, while n_bands= requests a fixed number of rows or columns. max_items_per_band= instead caps the number of signs in each band and lets the function determine how many bands are required. Use one of the two band controls, not both. SubwaySignOptions controls circle size, spacing, border, and text when the default key needs to match a report layout.

subway_signs(colors, labels, orientation="vertical", n_bands=2)
plt.show()
../../../../_images/b227513d6774c9412c8fad8bbf8129321e726d3925101c59a74cd5064e51e177.png