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')

 

这就是我想要的!

 
posted @ 2021-01-28 14:06  bH1pJ  阅读(30)  评论(0编辑  收藏  举报