DingWB / PyComplexHeatmap

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

support bar label ? #16

Open welyt opened 1 year ago

welyt commented 1 year ago

https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.7.0.html image

DingWB commented 1 year ago

bar_label is only available in the latest version of matplotlib. However, many users are using the lower version of matplotlib. So, it's not supported in PyComplexHeatmap now, which will be considered in the future. But you can implement it with a few simple lines of code:

# firtly, get the ax from HeatmapAnnotation, for example,
col_ha=HeatmapAnnotation(...)
for ann in col_ha.annotations:
    if isinstance(ann,PyComplexHeatmap.annotations.anno_barplot):
      # you can get the annotation label using `ann.label`
      ann.ax.bar_label(bar_container, fmt='{:,.0f}')
DingWB commented 1 year ago

If you are interested, you can contribute by adding bar_label to the source code if the version of matplotlib >= 3.7 and make a pull request.

welyt commented 1 year ago

If you are interested, you can contribute by adding bar_label to the source code if the version of matplotlib >= 3.7 and make a pull request.

Thanks for the invitation. I'll try it when I'm free

welyt commented 1 year ago

the code below works for my case, thank you

for ann in score_anno.values():
if isinstance(ann, ph.annotations.anno_barplot):
ann.ax.bar_label(ann.ax.containers[0], fmt='{:,.2f}')
ann.ax.set_xlim([1.2,0])

image

DingWB commented 1 year ago

Looks better. I suggest you use parameter orientation='right', cause the roataion of your xlabel is -90, and the anno_simple is on the left. Besides, I would suggest you use a smaller figsize, cause the legend looks very small.