less than 1 minute read

import polars as pl
import altair as alt

# make DatraFrame


df = pl.DataFrame( { 
    'a' : [ 1, 3 ,4 ], 
    'b' : [ 1, 3, 4 ],
    'c' : [ 3, 8, 4 ]
} )

# check corr


df_c = df.corr().with_columns(
    pl.Series( df.columns ).alias( 'col' )
).unpivot( index = 'col' )

# Visualiztion with altair


df_base = alt.Chart( df_c ).mark_rect().encode(
    alt.X( 'col' ).title( None ).axis( labelAngle = 0 ), 
    alt.Y( 'variable' ).title( None )
)

df_rect = df_base.mark_rect().encode(
    alt.Color( 'value' )
)

df_text = df_base.mark_text().encode(
    alt.Text( 'value' ).format( ',.2%' ), 
    color = alt.condition( 
        alt.datum.value > 0.8, alt.value( 'white' ), alt.value( 'gray' ) 
    )
)
alt.layer( 
    df_rect, df_text, width = 300, height = 300 
).configure_axis( labelFontSize = 13 )