From 129a32beb698a2e69653e51b2d67d548000fd7a3 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Sun, 6 Nov 2016 18:44:22 -1000 Subject: [PATCH] ENH: restore default ability to label some minor log ticks. This partly restores the functionality that was added in PR #5161 and partly removed in #7000. The "partly" is because now the labeling of minor log ticks is turned on only when numdecs (the axis range in powers of the log base) is less than or equal to one, rather than 3. This also fixes a bug that was causing double labeling with a base of 2; minor ticks were coinciding with major ticks, and both were being labeled. --- examples/pylab_examples/log_demo.py | 2 +- lib/matplotlib/scale.py | 2 +- lib/matplotlib/tests/test_ticker.py | 11 +++++++---- lib/matplotlib/ticker.py | 10 +++++----- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/pylab_examples/log_demo.py b/examples/pylab_examples/log_demo.py index bf7372191fc1..eeb30f36583b 100644 --- a/examples/pylab_examples/log_demo.py +++ b/examples/pylab_examples/log_demo.py @@ -21,7 +21,7 @@ plt.subplot(223) plt.loglog(t, 20*np.exp(-t/10.0), basex=2) plt.grid(True) -plt.title('loglog base 4 on x') +plt.title('loglog base 2 on x') # with errorbars: clip non-positive values ax = plt.subplot(224) diff --git a/lib/matplotlib/scale.py b/lib/matplotlib/scale.py index 8784ca495905..32359b46a9c5 100644 --- a/lib/matplotlib/scale.py +++ b/lib/matplotlib/scale.py @@ -306,7 +306,7 @@ def set_default_locators_and_formatters(self, axis): axis.set_major_locator(LogLocator(self.base)) axis.set_major_formatter(LogFormatterSciNotation(self.base)) axis.set_minor_locator(LogLocator(self.base, self.subs)) - axis.set_minor_formatter(NullFormatter()) + axis.set_minor_formatter(LogFormatterSciNotation(self.base, self.subs)) def get_transform(self): """ diff --git a/lib/matplotlib/tests/test_ticker.py b/lib/matplotlib/tests/test_ticker.py index 069c7c194a8d..531367658326 100644 --- a/lib/matplotlib/tests/test_ticker.py +++ b/lib/matplotlib/tests/test_ticker.py @@ -250,13 +250,16 @@ def test_LogFormatter_sublabel(): assert np.all(show_major_labels) _sub_labels(ax.xaxis, subs=[]) - # axis range at 2 to 3 decades, label sub 3 + # For the next two, if the numdec threshold in LogFormatter.set_locs + # were 3, then the label sub would be 3 for 2-3 decades and (2,5) + # for 1-2 decades. With a threshold of 1, subs are not labeled. + # axis range at 2 to 3 decades ax.set_xlim(1, 800) - _sub_labels(ax.xaxis, subs=[3]) + _sub_labels(ax.xaxis, subs=[]) - # axis range at 1 to 2 decades, label subs 2 and 5 + # axis range at 1 to 2 decades ax.set_xlim(1, 80) - _sub_labels(ax.xaxis, subs=[2, 5]) + _sub_labels(ax.xaxis, subs=[]) # axis range at 0 to 1 decades, label subs 2, 3, 6 ax.set_xlim(1, 8) diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index f274ba71a81a..2ab5eddc87d2 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -853,7 +853,7 @@ def set_locs(self, locs): vmax = math.log(vmax) / math.log(b) numdec = abs(vmax - vmin) - if numdec > 3: + if numdec > 1: # Label only bases self.sublabel = set((1,)) else: @@ -1857,10 +1857,10 @@ def tick_values(self, vmin, vmax): numdec = math.floor(vmax) - math.ceil(vmin) - if self._subs is None: # autosub - if numdec > 10: - subs = np.array([1.0]) - elif numdec > 6: + if self._subs is None: # autosub for minor ticks + if numdec > 10 or b < 3: + return np.array([]) # no minor ticks + elif numdec > 5 and b >= 6: subs = np.arange(2.0, b, 2.0) else: subs = np.arange(2.0, b)