Skip to content
Closed
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
5 changes: 5 additions & 0 deletions doc/users/next_whats_new/2019-11-29-pyplot-ticks-labels.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ticks' labels can now be set without passing ``ticks`` in pyplot
----------------------------------------------------------------

``pyplot.xticks()`` and ``pyplot.yticks()`` can now be used to set ticks'
labels without requiring to pass the ``ticks`` parameter.
18 changes: 10 additions & 8 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,15 +1428,16 @@ def xticks(ticks=None, labels=None, **kwargs):
"""
ax = gca()

if ticks is None and labels is None:
if ticks is None:
locs = ax.get_xticks()
labels = ax.get_xticklabels()
elif labels is None:
else:
locs = ax.set_xticks(ticks)

if labels is None:
labels = ax.get_xticklabels()
else:
locs = ax.set_xticks(ticks)
labels = ax.set_xticklabels(labels, **kwargs)

for l in labels:
l.update(kwargs)

Expand Down Expand Up @@ -1503,15 +1504,16 @@ def yticks(ticks=None, labels=None, **kwargs):
"""
ax = gca()

if ticks is None and labels is None:
if ticks is None:
locs = ax.get_yticks()
labels = ax.get_yticklabels()
elif labels is None:
else:
locs = ax.set_yticks(ticks)

if labels is None:
labels = ax.get_yticklabels()
else:
locs = ax.set_yticks(ticks)
labels = ax.set_yticklabels(labels, **kwargs)

for l in labels:
l.update(kwargs)

Expand Down