From 9bc809734eec911ae057396db84953cd96d33d51 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 25 Jun 2019 15:48:15 +0200 Subject: [PATCH] Fix axis inversion with loglocator and logitlocator. --- doc/api/next_api_changes/2019-03-04-AL.rst | 6 ------ doc/api/next_api_changes/2019-06-25-AL.rst | 7 +++++++ lib/matplotlib/dates.py | 5 ++++- lib/matplotlib/ticker.py | 4 ---- 4 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 doc/api/next_api_changes/2019-06-25-AL.rst diff --git a/doc/api/next_api_changes/2019-03-04-AL.rst b/doc/api/next_api_changes/2019-03-04-AL.rst index d7564328ba1d..22ee6a8788e3 100644 --- a/doc/api/next_api_changes/2019-03-04-AL.rst +++ b/doc/api/next_api_changes/2019-03-04-AL.rst @@ -47,9 +47,3 @@ properties of the `.Collection` object: While this seems complicated, the logic is simply to use the information from the object that are in data space for the limits, but not information that is in physical units. - -LogLocator.nonsingular now maintains the orders of its arguments -```````````````````````````````````````````````````````````````` - -It no longer reorders them in increasing order. The new behavior is consistent -with MaxNLocator. diff --git a/doc/api/next_api_changes/2019-06-25-AL.rst b/doc/api/next_api_changes/2019-06-25-AL.rst new file mode 100644 index 000000000000..9c5467d3f747 --- /dev/null +++ b/doc/api/next_api_changes/2019-06-25-AL.rst @@ -0,0 +1,7 @@ +API changes +``````````` + +``Locator.nonsingular`` (introduced in mpl 3.1), ``DateLocator.nonsingular``, and +``AutoDateLocator.nonsingular`` now returns a range ``v0, v1`` with ``v0 <= v1``. +This behavior is consistent with the implementation of ``nonsingular`` by the +``LogLocator`` and ``LogitLocator`` subclasses. diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 1b86cf07a0b1..350b6815b411 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -1117,8 +1117,9 @@ def nonsingular(self, vmin, vmax): """ Given the proposed upper and lower extent, adjust the range if it is too close to being singular (i.e. a range of ~0). - """ + if vmax < vmin: + vmin, vmax = vmax, vmin unit = self._get_unit() interval = self._get_interval() if abs(vmax - vmin) < 1e-6: @@ -1336,6 +1337,8 @@ def tick_values(self, vmin, vmax): def nonsingular(self, vmin, vmax): # whatever is thrown at us, we can scale the unit. # But default nonsingular date plots at an ~4 year period. + if vmax < vmin: + vmin, vmax = vmax, vmin if vmin == vmax: vmin = vmin - DAYS_PER_YEAR * 2 vmax = vmax + DAYS_PER_YEAR * 2 diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index ab8ba4dcfde8..38ad96e3b400 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -2495,9 +2495,7 @@ def view_limits(self, vmin, vmax): return vmin, vmax def nonsingular(self, vmin, vmax): - swap_vlims = False if vmin > vmax: - swap_vlims = True vmin, vmax = vmax, vmin if not np.isfinite(vmin) or not np.isfinite(vmax): vmin, vmax = 1, 10 # Initial range, no data plotted yet. @@ -2515,8 +2513,6 @@ def nonsingular(self, vmin, vmax): if vmin == vmax: vmin = _decade_less(vmin, self._base) vmax = _decade_greater(vmax, self._base) - if swap_vlims: - vmin, vmax = vmax, vmin return vmin, vmax