Open
Description
Bug report
Bug summary
bar_label currently uses the default annotation() clipping behavior, which is to draw the text unclipped as long as the annotated point is within the axes. I'm not sure this is the best behavior for this use case?
Code for reproduction
from pylab import *
ax = gca()
rs = ax.bar(np.arange(50), np.arange(50))
ax.bar_label(rs)
ax.set(ylim=(0, 40))
show()
Actual outcome
Note how the 39 and 40 labels are still drawn (effectively, because the bar tops are within axes limits), but not the subsequent ones.
Expected outcome
I'm not sure what the best behavior would be, but it should likely be one of the following:
- perform "normal" clipping (so 39 is half-clipped, 40 is fully clipped out)
- don't draw any labels that would be clipped (39 is hidden)
- don't clip at all (all labels are visible)
bar_label is new in 3.4 so it may be worth deciding on this before the 3.4 release.
Matplotlib version
- Operating system: linux
- Matplotlib version (
import matplotlib; print(matplotlib.__version__)
): head - Matplotlib backend (
print(matplotlib.get_backend())
): agg - Python version: 39
- Jupyter version (if applicable):
- Other libraries:
(inspired by #19428, but that bug report is using a pre-bar_label labeling approach.)