Add Second Colorbar to a Seaborn Heatmap / Clustermap

  • 0
  • Pump00:00

I was trying to help someone add a colorbar for the vertical blue bar in the image below. We tried many variations of plt.colorbar(row_colors) (like above and below sns.clustermap()) and looked around online for 2 hours, but no luck. We just want to add a colorbar for the blues, please help!

import pickle
import numpy as np
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

feat_mat, freq, label = pickle.load(open('file.pkl', 'rb'))

feat_mat_df = pd.DataFrame(feat_mat[4])

freq_df = pd.DataFrame(freq)
freq_df_transposed = freq_df.transpose()

my_palette = dict(zip(set(freq_df_transposed[int('4')]), sns.color_palette("PuBu", len(set(freq_df_transposed[int('4')]))))))
row_colors = freq_df_transposed[int('4')].map(my_palette)

sns.clustermap(feat_mat_df, metric="euclidean", standard_scale=1, method="complete", cmap="coolwarm", row_colors = row_colors)

plt.show()

IMAGE

This is where he based his code from: #405 Dendrogram with heatmap and coloured leaves

Default Asked on December 21, 2019 in Programming,   Python.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.