Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 80d0ac8

Browse filesBrowse files
anntzertacaswell
authored andcommitted
Backport PR #16006: Ignore pos in StrCategoryFormatter.__call__ to display correct label in the preview window
Ignore pos in StrCategoryFormatter.__call__ to display correct… (#16006) Ignore pos in StrCategoryFormatter.__call__ to display correct label in the preview window Conflicts: lib/matplotlib/tests/test_category.py - collision with py2 removal work (_to_str)
1 parent 0900819 commit 80d0ac8
Copy full SHA for 80d0ac8

File tree

Expand file treeCollapse file tree

2 files changed

+10
-5
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-5
lines changed

‎lib/matplotlib/category.py

Copy file name to clipboardExpand all lines: lib/matplotlib/category.py
+6-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_category.py
+4-4Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.