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

Skip to content

Backport PR #16006: Ignore pos in StrCategoryFormatter.__call__ to di… #16542

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
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
7 changes: 6 additions & 1 deletion lib/matplotlib/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ def __init__(self, units_mapping):
self._units = units_mapping

def __call__(self, x, pos=None):
return '' if pos is None else self.format_ticks([x])[0]
"""
Return the category label string for tick val *x*.

The position *pos* is ignored.
"""
return self.format_ticks([x])[0]

def format_ticks(self, values):
r_mapping = {v: self._text(k) for k, v in self._units.items()}
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/tests/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,16 @@ def test_StrCategoryFormatter(self, ax, ydata):
unit = cat.UnitData(ydata)
labels = cat.StrCategoryFormatter(unit._mapping)
for i, d in enumerate(ydata):
assert labels(i, i) == _to_str(d)
assert labels(i, i) == d
assert labels(i, None) == d

@pytest.mark.parametrize("ydata", cases, ids=ids)
@pytest.mark.parametrize("plotter", PLOT_LIST, ids=PLOT_IDS)
def test_StrCategoryFormatterPlot(self, ax, ydata, plotter):
plotter(ax, range(len(ydata)), ydata)
for i, d in enumerate(ydata):
assert ax.yaxis.major.formatter(i, i) == _to_str(d)
assert ax.yaxis.major.formatter(i+1, i+1) == ""
assert ax.yaxis.major.formatter(0, None) == ""
assert ax.yaxis.major.formatter(i) == d
assert ax.yaxis.major.formatter(i+1) == ""


def axis_test(axis, labels):
Expand Down