From 7d080f7d2020b044d6c141b22cceef83898efe21 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Thu, 16 May 2024 22:56:10 +1000 Subject: [PATCH] Display correlation values in AutoCorrelationsResult --- yli/descriptives.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/yli/descriptives.py b/yli/descriptives.py index 1ce4c9e..eabe30d 100644 --- a/yli/descriptives.py +++ b/yli/descriptives.py @@ -314,4 +314,19 @@ class AutoCorrelationsResult: """ import seaborn as sns - sns.heatmap(self.correlations, vmin=-1, vmax=1, cmap='RdBu') + + # Format values without leading 0 + def fmt_value(v): + if v >= 0.995: + return '1.0' + if v <= -0.995: + return '-1.0' + if v < 0: + if v >= -0.005: + return '.00' + return '-' + format(-v, '.2f').lstrip('0') + return format(v, '.2f').lstrip('0') + + correlation_values = self.correlations.applymap(fmt_value) + + sns.heatmap(self.correlations, vmin=-1, vmax=1, cmap='RdBu', annot=correlation_values, fmt='', annot_kws={'fontsize': 'small'})