Skip to content

Commit

Permalink
sty : simplify the reordering of the correlation matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
celprov committed Mar 24, 2023
1 parent 00ea0e8 commit 3f10199
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions mriqc_learn/viz/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,8 @@ def plot_corrmat(
"""
from mpl_toolkits.axes_grid1.inset_locator import inset_axes

# Cluster rows (if arguments enabled)
# Cluster rows and columns (if arguments enabled)
if sorted:
import pandas as pd
from scipy.cluster.hierarchy import linkage, dendrogram, fcluster

Z = linkage(data, 'complete', optimal_ordering=True)
Expand All @@ -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
Expand Down

0 comments on commit 3f10199

Please sign in to comment.