import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def
df = ex.set_labels(
load_kuznets()[["gini_regional", "gdp_pc", "log_gdp_pc"]],
load_kuznets_data_def(),
)
ex.explore_correlation_plot(df).figexplore_correlation_plot
explore_correlation_plot(df, *, style='heatmap', title=None, subtitle=None)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 (slice the columns first, then attach labels so the axes read nicely):
Advanced — the ellipse style (R corrplot look), with the underlying correlation matrix available from .df_corr:
import expdpy as ex
from expdpy.data import load_kuznets, load_kuznets_data_def
df = ex.set_labels(
load_kuznets()[["gini_regional", "gdp_pc", "log_gdp_pc", "trade_share"]],
load_kuznets_data_def(),
)
result = ex.explore_correlation_plot(df, style="ellipse")
result.fig
result.df_corr| gini_regional | gdp_pc | log_gdp_pc | trade_share | |
|---|---|---|---|---|
| gini_regional | 1.000000 | 0.202154 | -0.087637 | -0.154822 |
| gdp_pc | -0.190296 | 1.000000 | 0.824505 | -0.082082 |
| log_gdp_pc | -0.190296 | 1.000000 | 1.000000 | 0.027653 |
| trade_share | -0.148334 | 0.058316 | 0.058316 | 1.000000 |