Skip to content

Commit

Permalink
add annotations to cluster plot
Browse files Browse the repository at this point in the history
  • Loading branch information
chantelleleveille committed Oct 21, 2024
1 parent 13f5250 commit a8be049
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions nuc_morph_analysis/analyses/linear_regression/analysis_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,25 @@ def plot_feature_cluster_correlations(df_track_level_features, feature_list, fig
data = df_track_level_features[feature_list]

cluster_grid = sns.clustermap(data.corr(), vmin=-1, vmax=1, cmap='vlag',
cbar_pos=(0.45, 0.5, 0.18, 0.02),
cbar_kws={"orientation": "horizontal"})
cbar_pos=(0.7, 0.13, 0.18, 0.02),
cbar_kws={"orientation": "horizontal"},
annot=True, fmt=".1f", annot_kws={"size": 12},
figsize=(20, 20))

# Get the reordered labels using the dendrogram information
reordered_column_index = cluster_grid.dendrogram_col.reordered_ind

reordered_labels = [get_plot_labels_for_metric(data.columns[i])[1] for i in reordered_column_index]

# Ensure the number of labels matches the number of ticks
cluster_grid.ax_heatmap.set_xticks(range(len(reordered_labels)))
cluster_grid.ax_heatmap.set_xticks([x + 0.5 for x in range(len(reordered_labels))])
cluster_grid.ax_heatmap.set_xticklabels(reordered_labels, rotation=90)
cluster_grid.ax_heatmap.set_yticks(range(len(reordered_labels)))
cluster_grid.ax_heatmap.set_yticks([y + 0.5 for y in range(len(reordered_labels))])
cluster_grid.ax_heatmap.set_yticklabels(reordered_labels, rotation=0)

# Adjust the padding between the labels and the heatmap
cluster_grid.ax_heatmap.tick_params(axis='x', labelsize=8, width=0.7)
cluster_grid.ax_heatmap.tick_params(axis='y', labelsize=8, width=0.7)
cluster_grid.ax_heatmap.tick_params(axis='x', labelsize=12, width=0.7)
cluster_grid.ax_heatmap.tick_params(axis='y', labelsize=12, width=0.7)

save_and_show_plot(f'{figdir}/feature_correlation_clustermap', figure=cluster_grid.fig, dpi=300)

Expand Down

0 comments on commit a8be049

Please sign in to comment.