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
11 changes: 2 additions & 9 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2908,10 +2908,8 @@ def sign(x):

if orientation == "vertical":
extrema = max(y0, y1) if dat >= 0 else min(y0, y1)
length = abs(y0 - y1)
else: # horizontal
extrema = max(x0, x1) if dat >= 0 else min(x0, x1)
length = abs(x0 - x1)

if err is None or np.size(err) == 0:
endpt = extrema
Expand All @@ -2920,11 +2918,6 @@ def sign(x):
else: # horizontal
endpt = err[:, 0].max() if dat >= 0 else err[:, 0].min()

if label_type == "center":
value = sign(dat) * length
else: # edge
value = extrema

if label_type == "center":
xy = (0.5, 0.5)
kwargs["xycoords"] = (
Expand Down Expand Up @@ -2967,9 +2960,9 @@ def sign(x):

if lbl is None:
if isinstance(fmt, str):
lbl = cbook._auto_format_str(fmt, value)
lbl = cbook._auto_format_str(fmt, dat)
elif callable(fmt):
lbl = fmt(value)
lbl = fmt(dat)
else:
raise TypeError("fmt must be a str or callable")
annotation = self.annotate(lbl,
Expand Down
9 changes: 8 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from types import SimpleNamespace
import unittest.mock

import dateutil.tz
import dateutil

import numpy as np
from numpy import ma
Expand Down Expand Up @@ -9503,6 +9503,13 @@ def test_nan_barlabels():
assert np.allclose(ax.get_ylim(), (0.0, 3.0))


def test_int_fmt_bar_label():
fig, ax = plt.subplots()
bars = ax.bar(['foo', 'bar'], [5, 7])
labels = ax.bar_label(bars, fmt='{:d}')
assert [l.get_text() for l in labels] == ['5', '7']


def test_patch_bounds(): # PR 19078
fig, ax = plt.subplots()
ax.add_patch(mpatches.Wedge((0, -1), 1.05, 60, 120, width=0.1))
Expand Down
Loading