clustermap add a legend
colorVec1 = (["lightgray"] * (A.shape[0])
+ ["darkorange"] * (B.shape[0])
+ ["seagreen"] * (C.shape[0])
)
g = sns.clustermap(corr_totalData, robust=True, col_colors = colorVec1, row_colors = colorVec1, rasterized = True)
species = pd.Series(data=colorVec1)
lut = dict(zip(species.unique(), ['lightgray','darkorange','seagreen']))
from matplotlib.patches import Patch
handles = [Patch(facecolor=lut[name]) for name in lut]
plt.legend(handles, lut, title='experiment',
bbox_to_anchor=(1, 1), bbox_transform=plt.gcf().transFigure, loc='upper right')
这就是我想要的!

浙公网安备 33010602011771号