Skip to content

Correlation Matrix

heat_map() is a natural fit for correlation matrices — the symmetric structure and [-1, 1] value range map perfectly onto a divergent colormap, making strong positive and negative correlations immediately visible.

This example uses Fisher's Iris dataset: 150 samples across 3 species, with 4 numeric features (sepal/petal length and width).

import polars as pl
import polarise
from polarise.datasets import get_iris_data
df = get_iris_data()

corr_df = df[:, :-1].corr(label='features').with_columns(
    pl.col(pl.Float64).round(2)
)

Correlation matrix

{ cmap="CET_L19" · built-in or colorcet }

(corr_df.style()
        .heat_map(exclude='features', cmap='CET_L19')
        .footnote('source : UCI Machine Learning Repository — Fisher\'s Iris dataset')
        .fashion_grid()
        .show()
 )
features sepal_length sepal_width petal_length petal_width
sepal_length 1.0 -0.12 0.87 0.82
sepal_width -0.12 1.0 -0.43 -0.37
petal_length 0.87 -0.43 1.0 0.96
petal_width 0.82 -0.37 0.96 1.0
source: UCI Machine Learning Repository — Fisher's Iris dataset