diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index e712e1302544..cd03957dbbfa 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -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": diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 3c138f46e010..863e3e2f86a6 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -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]
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: