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

Skip to content

BUG: Return null Bbox when there is no intersection for bar_label center. #25681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 17, 2023
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