Parallel Coordinates
Visualize multivariate data by drawing one line per observation across parallel vertical axes. Hover a line to highlight it and see all values in the tooltip.
Basic usage
import polars as pl
from plotutils.parallel import plot_parallel_coordinates
df = pl.DataFrame({
"sepal_length": [5.1, 4.9, 7.0, 6.3, 6.5, 5.8],
"sepal_width": [3.5, 3.0, 3.2, 3.3, 2.8, 2.7],
"petal_length": [1.4, 1.4, 4.7, 4.4, 4.6, 5.1],
"petal_width": [0.2, 0.2, 1.4, 1.3, 1.5, 1.9],
"species": ["setosa", "setosa", "versicolor",
"versicolor", "virginica", "virginica"],
})
chart = plot_parallel_coordinates(
df,
columns=["sepal_length", "sepal_width", "petal_length", "petal_width"],
color_col="species",
)
Normalized
When columns have very different scales, use normalize=True to apply
min-max normalization so all axes share the 0–1 range:
chart = plot_parallel_coordinates(
df,
columns=["sepal_length", "sepal_width", "petal_length", "petal_width"],
color_col="species",
normalize=True,
)
Log transforms
When normalizing, you can apply a per-column transform before
normalization. Use transforms=["log", "linear", ...] to log-transform
specific columns (useful for skewed distributions):
chart = plot_parallel_coordinates(
df,
columns=["sepal_length", "sepal_width", "petal_length", "petal_width"],
color_col="species",
normalize=True,
transforms=["linear", "linear", "log", "log"],
)
Sample identifiers
Pass id_col to include a sample identifier in the tooltip:
df_with_id = df.with_columns(pl.Series("id", ["s1", "s2", "s3", "s4", "s5", "s6"]))
chart = plot_parallel_coordinates(
df_with_id,
columns=["sepal_length", "sepal_width", "petal_length", "petal_width"],
color_col="species",
id_col="id",
)
Reference
plotutils.parallel.plot_parallel_coordinates(df, columns, color_col=None, id_col=None, normalize=False, transforms=None, title='', width=600, height=400, opacity=0.5, highlight_opacity=1.0)
Parallel coordinates plot for multivariate data.
Each row of df is drawn as a poly-line that passes through one
vertical axis per column in columns. Hovering a line highlights
it and shows a tooltip with all column values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Input data. |
required |
columns
|
list[str]
|
Column names to display as parallel axes (left to right). |
required |
color_col
|
str or None
|
Optional column for color encoding (categorical). |
None
|
id_col
|
str or None
|
Optional column with sample identifiers, shown in tooltip. |
None
|
normalize
|
bool
|
If True, apply min-max normalization to each column so all axes share the 0–1 range. |
False
|
transforms
|
list of {"linear", "log"} or None
|
Per-column transform applied before normalization. Must have
the same length as |
None
|
title
|
str
|
Chart title. |
''
|
width
|
int
|
Chart width in pixels. |
600
|
height
|
int
|
Chart height in pixels. |
400
|
opacity
|
float
|
Default line opacity for unselected lines. |
0.5
|
highlight_opacity
|
float
|
Line opacity when highlighted on mouseover. |
1.0
|
Returns:
| Type | Description |
|---|---|
LayerChart
|
|
Source code in src/plotutils/parallel.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |