Turn a directed source-to-destination matrix into an auditable chord layout without hiding self-flows or double-counting totals.
Chord diagrams: audit directed flows before drawing ribbons
Fix the unit and direction first
A chord diagram curls a square flow matrix around a circle. One row identifies the source; one column identifies the destination. A matrix entry can represent parcels moved between depots, but it cannot mix parcel count with shipment value. Decide whether the story is directed before any ribbons are drawn: a transfer from North to East is not the same record as East to North. If the values describe mutual relationships rather than movements, use an undirected contract and explain how two mirrored cells are consolidated. Network graphs emphasize topology; chords emphasize the volume between a manageable set of named groups. Their apparent symmetry can mislead readers when source and destination have different meanings, so label the ends or use a visible directional cue.
Reconcile sectors and ribbons
For a directed matrix, the outbound total of a group is its row sum and inbound total is its column sum. Decide whether each sector encodes outbound alone or inbound plus outbound; otherwise a sector width may appear to contradict its label. The worked contract below reports both. A transfer from a group to itself belongs on the diagonal and must be kept or explicitly excluded. Draw a self-loop distinctly because it can consume a large share of an arc without crossing the center. A ribbon should have an auditable value in an accompanying table. Sankey diagrams are often clearer when a process has ordered stages and conservation across them must be inspected.
Keep categories and filters stable
Arc order changes which ribbons overlap and can make the same data look dense or sparse. Set one documented category order across periods and filtered views. If an unseen group is grouped into Other, publish which group IDs it contains and keep its membership fixed when comparing periods. An interaction should reveal source, destination, amount, unit, time window and whether the value is a self-loop. It should also disclose the current filter cohort. Linked filter state is part of the reading contract: a selected destination must not silently redefine the total behind each sector. Export the full matrix rather than only the visible top ribbons.
Use density as a stopping rule
With 47 groups, there can be 2,209 directed cells before any filtering. Even a complete and accurate chord can become an unreadable knot. Start with a ranked table, a small set of stable groups or a matrix heatmap when precise cell comparisons matter. Heatmaps preserve a fixed row-column grid and make absent flows easier to spot. If the chord is retained, annotate whether zeros mean no observed movement or unavailable data, and provide text alternatives for keyboard and screen-reader access. Test the display at narrow widths; hiding labels does not remove the underlying ambiguity.
Worked contract
def directed_flow_ledger(groups: list[str],
flows: dict[tuple[str, str], int]):
if not groups or len(groups) != len(set(groups)) or any(not name for name in groups):
raise ValueError("group names must be unique and nonempty")
known = set(groups)
if any(source not in known or target not in known or
type(amount) is not int or amount < 0
for (source, target), amount in flows.items()):
raise ValueError("flow endpoints and amounts must be valid")
matrix = [[flows.get((source, target), 0) for target in groups]
for source in groups]
outbound = {source: sum(matrix[index])
for index, source in enumerate(groups)}
inbound = {target: sum(matrix[index][column]
for index in range(len(groups)))
for column, target in enumerate(groups)}
assert sum(outbound.values()) == sum(inbound.values())
return matrix, outbound, inbound
depots = ["North", "East", "West"]
transfers = {("North", "East"): 47, ("East", "North"): 13,
("North", "North"): 5, ("West", "East"): 29}
matrix, outbound, inbound = directed_flow_ledger(depots, transfers)
assert matrix[0] == [5, 47, 0]
assert outbound["North"] == 52
assert inbound["East"] == 76
assert sum(outbound.values()) == 94Performance and operating cost
For G groups, matrix construction takes O(G²) time and O(G²) space even when most flows are zero. The sparse input map is better for storage and for very large networks; the dense matrix is useful only when the chosen renderer requires it. The ledger counts each directed transfer once, including a self-loop, and proves that aggregate outbound equals aggregate inbound. It does not turn the chart into a conservation model across time: inventory changes and external entries still require their own rows.
Common Mistakes
- Adding both directions into one ribbon while calling the result directed.
- Dropping self-loops because they do not cross the circle.
- Changing arc order or the membership of Other between comparison panels.
- Treating an unavailable matrix cell as an observed zero.
Validation drill
Audit 59 transfer routes between five depots. Reconcile each outbound and inbound subtotal, then compare a chord with a matrix table at phone width.
Read next
- Sankey diagrams: reconcile flows before sizing links
- Network graphs: define nodes and edges before trusting the layout
- Heatmaps: make missing cells, rates and color domains explicit
- Interactive dashboards: recompute cohorts after linked filters
