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

Skip to content

Commit 44ccb0e

Browse files
authored
Ignore pos in StrCategoryFormatter.__call__ to display correct… (#16006)
Ignore pos in StrCategoryFormatter.__call__ to display correct label in the preview window
2 parents 981b82e + 9f1cae6 commit 44ccb0e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ def test_StrCategoryFormatter(self, ax, ydata):
154154
labels = cat.StrCategoryFormatter(unit._mapping)
155155
for i, d in enumerate(ydata):
156156
assert labels(i, i) == d
157+
assert labels(i, None) == d
157158

158159
@pytest.mark.parametrize("ydata", cases, ids=ids)
159160
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
160161
def test_StrCategoryFormatterPlot(self, ax, ydata, plotter):
161162
plotter(ax, range(len(ydata)), ydata)
162163
for i, d in enumerate(ydata):
163-
assert ax.yaxis.major.formatter(i, i) == d
164-
assert ax.yaxis.major.formatter(i+1, i+1) == ""
165-
assert ax.yaxis.major.formatter(0, None) == ""
164+
assert ax.yaxis.major.formatter(i) == d
165+
assert ax.yaxis.major.formatter(i+1) == ""
166166

167167

168168
def axis_test(axis, labels):

0 commit comments

Comments
 (0)