Skip to content

Commit 0e7f29e

Browse files
authored
Merge pull request #25681 from stefmolin/null-bbox
BUG: Return null Bbox when there is no intersection for bar_label center.
2 parents 8f16372 + 7037e85 commit 0e7f29e

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
@@ -8040,6 +8040,19 @@ def test_centered_bar_label_nonlinear():
80408040
ax.set_axis_off()
80418041

80428042

8043+
def test_centered_bar_label_label_beyond_limits():
8044+
fig, ax = plt.subplots()
8045+
8046+
last = 0
8047+
for label, value in zip(['a', 'b', 'c'], [10, 20, 50]):
8048+
bar_container = ax.barh('col', value, label=label, left=last)
8049+
ax.bar_label(bar_container, label_type='center')
8050+
last += value
8051+
ax.set_xlim(None, 20)
8052+
8053+
fig.draw_without_rendering()
8054+
8055+
80438056
def test_bar_label_location_errorbars():
80448057
ax = plt.gca()
80458058
xs, heights = [1, 2], [3, -4]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

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:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy