Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support bar label ? #16

Open
welyt opened this issue Feb 28, 2023 · 5 comments
Open

support bar label ? #16

welyt opened this issue Feb 28, 2023 · 5 comments

Comments

@welyt
Copy link
Contributor

welyt commented Feb 28, 2023

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

@DingWB
Copy link
Owner

DingWB commented Feb 28, 2023

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
Copy link
Owner

DingWB commented Feb 28, 2023

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
Copy link
Contributor Author

welyt commented Mar 1, 2023

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
Copy link
Contributor Author

welyt commented Mar 2, 2023

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
Copy link
Owner

DingWB commented Mar 2, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants