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

Skip to content

Commit d15be69

Browse files
authored
Merge pull request #16542 from tacaswell/auto-backport-of-pr-16006-on-v3.2.x
Backport PR #16006: Ignore pos in StrCategoryFormatter.__call__ to di…
2 parents 26e5801 + 80d0ac8 commit d15be69

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/matplotlib/category.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ def __init__(self, units_mapping):
138138
self._units = units_mapping
139139

140140
def __call__(self, x, pos=None):
141-
return '' if pos is None else self.format_ticks([x])[0]
141+
"""
142+
Return the category label string for tick val *x*.
143+
144+
The position *pos* is ignored.
145+
"""
146+
return self.format_ticks([x])[0]
142147

143148
def format_ticks(self, values):
144149
r_mapping = {v: self._text(k) for k, v in self._units.items()}

lib/matplotlib/tests/test_category.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ def test_StrCategoryFormatter(self, ax, ydata):
156156
unit = cat.UnitData(ydata)
157157
labels = cat.StrCategoryFormatter(unit._mapping)
158158
for i, d in enumerate(ydata):
159-
assert labels(i, i) == _to_str(d)
159+
assert labels(i, i) == d
160+
assert labels(i, None) == d
160161

161162
@pytest.mark.parametrize("ydata", cases, ids=ids)
162163
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
163164
def test_StrCategoryFormatterPlot(self, ax, ydata, plotter):
164165
plotter(ax, range(len(ydata)), ydata)
165166
for i, d in enumerate(ydata):
166-
assert ax.yaxis.major.formatter(i, i) == _to_str(d)
167-
assert ax.yaxis.major.formatter(i+1, i+1) == ""
168-
assert ax.yaxis.major.formatter(0, None) == ""
167+
assert ax.yaxis.major.formatter(i) == d
168+
assert ax.yaxis.major.formatter(i+1) == ""
169169

170170

171171
def axis_test(axis, labels):

0 commit comments

Comments
 (0)