diff --git a/doc/users/next_whats_new/2019-11-29-pyplot-ticks-labels.rst b/doc/users/next_whats_new/2019-11-29-pyplot-ticks-labels.rst new file mode 100644 index 000000000000..da34b368bd74 --- /dev/null +++ b/doc/users/next_whats_new/2019-11-29-pyplot-ticks-labels.rst @@ -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. \ No newline at end of file diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 3a08cec7ad1c..3eb7a1b16400 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -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) @@ -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)