8000 ENH: Validate kwargs in Axis.set_ticks() · matplotlib/matplotlib@97058fc · GitHub
[go: up one dir, main page]

Skip to content

Commit 97058fc

Browse files
committed
ENH: Validate kwargs in Axis.set_ticks()
1 parent 25d30c2 commit 97058fc

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/matplotlib/axis.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,9 @@ def set_ticks(self, ticks, labels=None, *, minor=False, **kwargs):
20292029
other limits, you should set the limits explicitly after setting the
20302030
ticks.
20312031
"""
2032+
if labels is None and kwargs:
2033+
raise ValueError('labels keyword argument cannot be None when '
2034+
'kwargs are passed')
20322035
result = self._set_tick_locations(ticks, minor=minor)
20332036
if labels is not None:
20342037
self.set_ticklabels(labels, minor=minor, **kwargs)

lib/matplotlib/tests/test_axes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5732,6 +5732,17 @@ def test_set_get_ticklabels():
57325732
ax[1].set_yticklabels(ax[0].get_yticklabels())
57335733

57345734

5735+
def test_set_ticks_kwargs_raise_error_without_labels():
5736+
"""
5737+
When labels=None and any kwarg is passed, axis.set_ticks() raises a
5738+
ValueError.
5739+
"""
5740+
fig, ax = plt.subplots()
5741+
ticks = [1, 2, 3]
5742+
with pytest.raises(ValueError):
5743+
ax.set_xticks(ticks, alpha=0.5)
5744+
5745+
57355746
@check_figures_equal(extensions=["png"])
57365747
def test_set_ticks_with_labels(fig_test, fig_ref):
57375748
"""

0 commit comments

Comments
 (0)
0