From 97fd28bd7ad0d03b3bedaf10fbb9fcbcb6e2bc88 Mon Sep 17 00:00:00 2001 From: cprovins Date: Fri, 24 Mar 2023 13:45:08 +0100 Subject: [PATCH] sty : simplify the reordering of the correlation matrix --- mriqc_learn/viz/metrics.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/mriqc_learn/viz/metrics.py b/mriqc_learn/viz/metrics.py index 9001a54..97beff0 100644 --- a/mriqc_learn/viz/metrics.py +++ b/mriqc_learn/viz/metrics.py @@ -215,7 +215,6 @@ def plot_corrmat( # Cluster rows (if arguments enabled) if sorted: - import pandas as pd from scipy.cluster.hierarchy import linkage, dendrogram, fcluster Z = linkage(data, 'complete', optimal_ordering=True) @@ -228,14 +227,8 @@ def plot_corrmat( # Keep the indices to sort labels labels_order = np.argsort(labels) - # Build a new dataframe with the sorted columns - for idx, i in enumerate(data.columns[labels_order]): - if idx == 0: - clustered = pd.DataFrame(data[i]) - else: - df_to_append = pd.DataFrame(data[i]) - clustered = pd.concat([clustered, df_to_append], axis=1) - data = clustered + # Reorder data + data = data.take(labels_order, axis=0).take(labels_order, axis=1) if hasattr(data, "columns"): col_labels = data.columns