8000 ENH: Check labels arg when kwargs passed in Axis.set_ticks() by j1642 · Pull Request #24334 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

ENH: Check labels arg when kwargs passed in Axis.set_ticks() #24334

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 1 commit into from
Nov 14, 2022
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
3 changes: 3 additions & 0 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,9 @@ def set_ticks(self, ticks, labels=None, *, minor=False, **kwargs):
other limits, you should set the limits explicitly after setting the
ticks.
"""
if labels is None and kwargs:
raise ValueError('labels argument cannot be None when '
'kwargs are passed')
result = self._set_tick_locations(ticks, minor=minor)
if labels is not None:
self.set_ticklabels(labels, minor=minor, **kwargs)
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5732,6 +5732,17 @@ def test_set_get_ticklabels():
ax[1].set_yticklabels(ax[0].get_yticklabels())


def test_set_ticks_kwargs_raise_error_without_labels():
"""
When labels=None and any kwarg is passed, axis.set_ticks() raises a
ValueError.
"""
fig, ax = plt.subplots()
ticks = [1, 2, 3]
with pytest.raises(ValueError):
ax.xaxis.set_ticks(ticks, alpha=0.5)


@check_figures_equal(extensions=["png"])
def test_set_ticks_with_labels(fig_test, fig_ref):
"""
Expand Down
0