-
Hi @DingWB , Thank you for developing such an excellent tool! I am currently working with PyComplexHeatmap and encountered a specific need regarding the order of the legend. In the example provided here, I would like to modify the order of the legend so that it displays "AB" followed by "CD." Could you kindly guide me on how to customize the legend's order in this scenario? Below is an image to illustrate what I mean: Thank you in advance for your help! Best, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hi @WeipengMO , This is an interesting problem, I have never thought about it. plt.figure(figsize=(4, 8))
col_ha = HeatmapAnnotation(
**, plot=False
)
# change the order of legend_list
col_ha.legend_list=[col_ha.legend_list[i] for i in [the target order]]
col_ha.plot_annotations()
plt.show() Similarly, for ClusterMapPlotter: plt.figure(figsize=(4, 8))
cm = ClusterMapPlotter(
**, plot=False
)
# change the order of legend_list
cm.legend_list=[cm.legend_list[i] for i in [the target order]]
cm.plot()
# if plot_legend:
# if legend_anchor == "auto":
if (
not cm.right_annotation is None
and cm.legend_side == "right"
):
legend_anchor = "ax"
else:
legend_anchor = "ax_heatmap"
if legend_anchor == "ax_heatmap":
cm.plot_legends(ax=cm.ax_heatmap)
else:
cm.plot_legends(ax=cm.ax)
cm.post_processing()
plt.show() |
Beta Was this translation helpful? Give feedback.
-
Hi @WeipengMO , As you requested, I just added a parameter legend_order: str, bool or list Could you please install the latest version from Github ( |
Beta Was this translation helpful? Give feedback.
Hi @WeipengMO ,
This is an interesting problem, I have never thought about it.
The order of legends is determined by the variable
legend_list
, I would suggest you change the order ofself.legend_list
and plot. For example:For annotations only:
Similarly, for ClusterMapPlotter: