Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 652d317

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

File tree

Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-0
lines changed
Open diff view settings
Collapse file

‎lib/matplotlib/axis.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+3Lines 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)
Collapse file

‎lib/matplotlib/tests/test_axes.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+11Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.