Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2769,7 +2769,7 @@ def sign(x):
lambda r, b=bar:
mtransforms.Bbox.intersection(
b.get_window_extent(r), b.get_clip_box()
)
) or mtransforms.Bbox.null()
)
else: # edge
if orientation == "vertical":
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8040,6 +8040,19 @@ def test_centered_bar_label_nonlinear():
ax.set_axis_off()


def test_centered_bar_label_label_beyond_limits():
fig, ax = plt.subplots()

last = 0
for label, value in zip(['a', 'b', 'c'], [10, 20, 50]):
bar_container = ax.barh('col', value, label=label, left=last)
ax.bar_label(bar_container, label_type='center')
last += value
ax.set_xlim(None, 20)

fig.draw_without_rendering()


def test_bar_label_location_errorbars():
ax = plt.gca()
xs, heights = [1, 2], [3, -4]
Expand Down