8000 Ignore pos in StrCategoryFormatter.__call__ to display correct label in the preview window by sujanasowrirajan · Pull Request #16006 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Ignore pos in StrCategoryFormatter.__call__ to display correct label in the preview window #16006

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 2 commits into from
Jan 2, 2020
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
6 changes: 3 additions & 3 deletions lib/matplotlib/tests/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ def test_StrCategoryFormatter(self, ax, ydata):
labels = cat.StrCategoryFormatter(unit._mapping)
for i, d in enumerate(ydata):
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) == 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) == ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test that ax.yaxis.major.formatter(i, None) gives d as the label? (which it wouldn't do before this fix)

Copy link
Contributor Author

Choose a reason for hiding thi 5EBA s comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have updated the test.



def axis_test(axis, labels):
Expand Down
0