Skip to content
svgbrushableparallel-coords

Parallel coordinates

How do rows compare across many numeric variables at once?

Demo data · seed 20261101 · 300 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Each line is one row, crossing every axis at its value.
  2. Lines running parallel between two axes: those variables move together; lines crossing in an X: they move oppositely.
  3. Drag on an axis to select a range and see those rows light up.
  1. Callout 1: Each axis is scaled to its own minimum and maximum.
  2. Callout 2: Lines crossing in an X: the two variables move oppositely.
  3. Callout 3: Colour marks the group.

Watch out

  • Axis order changes which patterns you can see, and many rows turn into a solid mass.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Each axis is min–max scaled to its own observed range (labels show min and max); a missing value breaks that row's line.
  • Line opacity ≈ 6/√n (clamped to [0.08, 0.5]) so dense regions read as density.
  • Brushing an axis selects rows whose value lies in the brushed range; brushes on several axes combine with AND.
# Parallel coordinates — Codesplash Chart Lab (recipe "parallel-coords")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("parallel-coords-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["origin"] = pd.Categorical(df["origin"].astype("string"), categories=["USA", "Europe", "Japan"])

def freq_levels(s, k=8):
    """Declared level order when the column is categorical, else by descending count (ties A→Z)."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [str(v) for v in s.cat.categories][:k]
    vc = s.dropna().astype(str).value_counts()
    return sorted(vc.index, key=lambda v: (-vc[v], v))[:k]
def stride(frame, k):
    if len(frame) <= k:
        return frame
    return frame.iloc[np.floor(np.arange(k) * len(frame) / k).astype(int)]

VARS = ["mpg", "cylinders", "displacement", "horsepower", "weight", "acceleration"]
d = stride(df, 1500)  # at most 1,500 lines (deterministic stride)
lo, hi = df[VARS].min(), df[VARS].max()
scaled = (d[VARS] - lo) / (hi - lo).replace(0, 1)  # each axis min–max scaled to its own range
alpha = float(np.clip(6 / np.sqrt(len(d)), 0.08, 0.5))
fig, ax = plt.subplots(figsize=(8, 4.5))
xs = np.arange(len(VARS))
colours = {lv: PALETTE[i % len(PALETTE)] for i, lv in enumerate(freq_levels(df["origin"]))}
for row, g in zip(scaled.to_numpy(), d["origin"].astype(str)):
    ax.plot(xs, row, color=colours.get(g, PALETTE[7]), alpha=alpha, linewidth=0.8)  # a missing value breaks the line
for lv, col in colours.items():
    ax.plot([], [], color=col, label=lv)
ax.legend(title="origin", fontsize=8, loc="upper right")
for i, v in enumerate(VARS):
    ax.axvline(i, color="#6c727b", linewidth=0.8)
    ax.text(i, -0.04, f"{lo[v]:.4g}", ha="center", va="top", fontsize=7)
    ax.text(i, 1.04, f"{hi[v]:.4g}", ha="center", va="bottom", fontsize=7)
ax.set_xticks(xs, VARS)
ax.set_yticks([])
ax.set_ylim(-0.12, 1.12)
ax.grid(False)
plt.show()

Needs pandas, numpy, matplotlib · reads parallel-coords-demo.csv · app theme from the optional codesplash helper