From 58feee2e9001f8171d42c16e069e861ddf391974 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Thu, 28 Nov 2019 14:16:45 +0000 Subject: [PATCH 1/4] Fixes and cleans code related to pyplot xticks() and yticks() to allow setting only the labels --- lib/matplotlib/pyplot.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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) From 31f332ec239cb0f26b17dfa826a151af1889c1d5 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Fri, 29 Nov 2019 15:27:26 +0000 Subject: [PATCH 2/4] Adds description of new feature to next_whats_new --- doc/users/next_whats_new/2019-11-29-pyplot-ticks-labels.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/users/next_whats_new/2019-11-29-pyplot-ticks-labels.rst 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..c1ac5f22f42c --- /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 `locs` in pyplot +------------------------------------------------------------- + +`pyplot.xticks()` and `pyplot.yticks()` can now be used to set ticks' labels without +requiring to pass the `locs` parameter. \ No newline at end of file From efdb4aa8356b05a83c1488d831628df3736d6572 Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Fri, 29 Nov 2019 15:47:48 +0000 Subject: [PATCH 3/4] Fixes typo from last commit in next_whats_new file --- doc/users/next_whats_new/2019-11-29-pyplot-ticks-labels.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 index c1ac5f22f42c..b04d96ae913b 100644 --- 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 @@ -1,5 +1,5 @@ -ticks' labels can now be set without passing `locs` in pyplot -------------------------------------------------------------- +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 `locs` parameter. \ No newline at end of file +requiring to pass the `ticks` parameter. \ No newline at end of file From 77f62ebc2a8de53409acbdc6b305585cf2b27d5b Mon Sep 17 00:00:00 2001 From: Ricardo Mendes Date: Fri, 29 Nov 2019 17:29:54 +0000 Subject: [PATCH 4/4] Fixes documentation from previous commit --- .../next_whats_new/2019-11-29-pyplot-ticks-labels.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 index b04d96ae913b..da34b368bd74 100644 --- 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 @@ -1,5 +1,5 @@ -ticks' labels can now be set without passing `ticks` in pyplot --------------------------------------------------------------- +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 +``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