DingWB / PyComplexHeatmap

PyComplexHeatmap: A Python package to plot complex heatmap (clustermap)
https://dingwb.github.io/PyComplexHeatmap/
MIT License
249 stars 28 forks source link

Re-order labels in legend #69

Closed mbernste closed 3 months ago

mbernste commented 3 months ago

Hi,

Thank you so much for this great package! Is it possible to re-order labels within a legend created by anno_simple?

For example, in this quick example, how would one re-order the labels in the "CD" annotation from being "C", "D", "G" to, say, "G", "D", "C" in the legend?

Thank you so much!

Best, Matt

DingWB commented 3 months ago

Hi @mbernste ,

Thanks for your question. Actually, for this example, it's very simple, just change the code from

CD=anno_simple(df.CD,add_text=True,colors={'C':'tomato','D':'yellowgreen','G':'skyblue'},
                                            legend_kws={'frameon':False}),

to

CD=anno_simple(df.CD,add_text=True,colors={'G':'skyblue','D':'yellowgreen','C':'tomato'},
                                            legend_kws={'frameon':False}),

If colors is not given and one would like to use cmap to indicate colors. Then you can change the order of df.CD and the order of the labels in the legend would be changed too.