From fd639b3cb6cbd2995e3b732749dfe60622926f33 Mon Sep 17 00:00:00 2001 From: Evangelos Lamprou Date: Tue, 14 Jan 2025 09:07:40 -0500 Subject: [PATCH] Update syntax viz Signed-off-by: Evangelos Lamprou --- infrastructure/viz/syntax.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/infrastructure/viz/syntax.py b/infrastructure/viz/syntax.py index 8003a756..35c1f920 100644 --- a/infrastructure/viz/syntax.py +++ b/infrastructure/viz/syntax.py @@ -122,10 +122,26 @@ def node_heatmap(df, outdir=None): # order the y-axis of the heatmap according to the node_order, any nodes not in that list can appear after in any order heatmap_data = heatmap_data.loc[[x for x in heatmap_data.index if x not in node_order] + list(reversed(node_order))] annot_data = annot_data.loc[[x for x in annot_data.index if x not in node_order] + list(reversed(node_order))] + + # Sort the columns by the sum of the values in each column + heatmap_data = heatmap_data[heatmap_data.sum().sort_values(ascending=False).index] + annot_data = annot_data[heatmap_data.columns] + + # Add an overall total column, this should be outside the normalizations + heatmap_data['total'] = heatmap_data.sum(axis=1) + annot_data['total'] = annot_data.sum(axis=1) + + heatmap_data = heatmap_data.applymap(lambda x: min(x, limit)) + annot_data = heatmap_data.applymap(lambda x: \ + #'>{}'.format(limit) \ + '*' \ + if x == limit else '') + + # Set the color limit to be 5 plt.figure(figsize=(5.5, 6)) sns.heatmap(heatmap_data, - cmap='Reds', + cmap='Greys', annot=annot_data, fmt='', cbar_kws={'label': 'Occurrences (* denotes more than 5)',