Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 08e6dc1

Browse files
authored
Merge pull request #25705 from meeseeksmachine/auto-backport-of-pr-25681-on-v3.7.x
Backport PR #25681 on branch v3.7.x (BUG: Return null Bbox when there is no intersection for bar_label center.)
2 parents d96f8a4 + 786812e commit 08e6dc1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2769,7 +2769,7 @@ def sign(x):
27692769
lambda r, b=bar:
27702770
mtransforms.Bbox.intersection(
27712771
b.get_window_extent(r), b.get_clip_box()
2772-
)
2772+
) or mtransforms.Bbox.null()
27732773
)
27742774
else: # edge
27752775
if orientation == "vertical":

lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8008,6 +8008,19 @@ def test_centered_bar_label_nonlinear():
80088008
ax.set_axis_off()
80098009

80108010

8011+
def test_centered_bar_label_label_beyond_limits():
8012+
fig, ax = plt.subplots()
8013+
8014+
last = 0
8015+
for label, value in zip(['a', 'b', 'c'], [10, 20, 50]):
8016+
bar_container = ax.barh('col', value, label=label, left=last)
8017+
ax.bar_label(bar_container, label_type='center')
8018+
last += value
8019+
ax.set_xlim(None, 20)
8020+
8021+
fig.draw_without_rendering()
8022+
8023+
80118024
def test_bar_label_location_errorbars():
80128025
ax = plt.gca()
80138026
xs, heights = [1, 2], [3, -4]

0 commit comments

Comments
 (0)