prepare_correlation_graph

prepare_correlation_graph(df, *, style='heatmap')

Visualise a correlation matrix (Pearson above, Spearman below the diagonal).

Parameters

Name Type Description Default
df pd.DataFrame Data frame with at least two numeric/logical variables and five observations. required
style Literal['heatmap', 'ellipse'] "heatmap" (default) renders a Plotly heatmap; "ellipse" reproduces R’s corrplot(method = "ellipse") look with one ellipse glyph per cell. 'heatmap'

Returns

Name Type Description
CorrelationGraphResult df_corr/df_prob/df_n plus the Plotly fig.

Examples

Basic — a correlation heatmap for a few variables:

import expdpy as ex
from expdpy.data import load_kuznets

df = load_kuznets()
ex.prepare_correlation_graph(df[["gini_regional", "gdp_pc", "log_gdp_pc"]]).fig

Advanced — the ellipse style (R corrplot look), with the underlying correlation matrix available from .df_corr:

result = ex.prepare_correlation_graph(
    df[["gini_regional", "gdp_pc", "log_gdp_pc", "trade_share"]],
    style="ellipse",
)
result.fig
result.df_corr