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

Skip to content

Commit 652d317

Browse files
authored
Merge pull request matplotlib#24334 from j1642/validate-set_ticks-kwargs
ENH: Check labels arg when kwargs passed in Axis.set_ticks()
2 parents 500967b + d9cd5cd commit 652d317

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
@@ -2021,6 +2021,9 @@ def set_ticks(self, ticks, labels=None, *, minor=False, **kwargs):
20212021
other limits, you should set the limits explicitly after setting the
20222022
ticks.
20232023
"""
2024+
if labels is None and kwargs:
2025+
raise ValueError('labels argument cannot be None when '
2026+
'kwargs are passed')
20242027
result = self._set_tick_locations(ticks, minor=minor)
20252028
if labels is not None:
20262029
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
@@ -5735,6 +5735,17 @@ def test_set_get_ticklabels():
57355735
ax[1].set_yticklabels(ax[0].get_yticklabels())
57365736

57375737

5738+
def test_set_ticks_kwargs_raise_error_without_labels():
5739+
"""
5740+
When labels=None and any kwarg is passed, axis.set_ticks() raises a
5741+
ValueError.
5742+
"""
5743+
fig, ax = plt.subplots()
5744+
ticks = [1, 2, 3]
5745+
with pytest.raises(ValueError):
5746+
ax.xaxis.set_ticks(ticks, alpha=0.5)
5747+
5748+
57385749
@check_figures_equal(extensions=["png"])
57395750
def test_set_ticks_with_labels(fig_test, fig_ref):
57405751
"""

0 commit comments

Comments
 (0)