Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 129a32b

Browse files
committed
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.
1 parent cb21ba7 commit 129a32b

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

examples/pylab_examples/log_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
plt.subplot(223)
2222
plt.loglog(t, 20*np.exp(-t/10.0), basex=2)
2323
plt.grid(True)
24-
plt.title('loglog base 4 on x')
24+
plt.title('loglog base 2 on x')
2525

2626
# with errorbars: clip non-positive values
2727
ax = plt.subplot(224)

lib/matplotlib/scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def set_default_locators_and_formatters(self, axis):
306306
axis.set_major_locator(LogLocator(self.base))
307307
axis.set_major_formatter(LogFormatterSciNotation(self.base))
308308
axis.set_minor_locator(LogLocator(self.base, self.subs))
309-
axis.set_minor_formatter(NullFormatter())
309+
axis.set_minor_formatter(LogFormatterSciNotation(self.base, self.subs))
310310

311311
def get_transform(self):
312312
"""

lib/matplotlib/tests/test_ticker.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,16 @@ def test_LogFormatter_sublabel():
250250
assert np.all(show_major_labels)
251251
_sub_labels(ax.xaxis, subs=[])
252252

253-
# axis range at 2 to 3 decades, label sub 3
253+
# For the next two, if the numdec threshold in LogFormatter.set_locs
254+
# were 3, then the label sub would be 3 for 2-3 decades and (2,5)
255+
# for 1-2 decades. With a threshold of 1, subs are not labeled.
256+
# axis range at 2 to 3 decades
254257
ax.set_xlim(1, 800)
255-
_sub_labels(ax.xaxis, subs=[3])
258+
_sub_labels(ax.xaxis, subs=[])
256259

257-
# axis range at 1 to 2 decades, label subs 2 and 5
260+
# axis range at 1 to 2 decades
258261
ax.set_xlim(1, 80)
259-
_sub_labels(ax.xaxis, subs=[2, 5])
262+
_sub_labels(ax.xaxis, subs=[])
260263

261264
# axis range at 0 to 1 decades, label subs 2, 3, 6
262265
ax.set_xlim(1, 8)

lib/matplotlib/ticker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ def set_locs(self, locs):
853853
vmax = math.log(vmax) / math.log(b)
854854
numdec = abs(vmax - vmin)
855855

856-
if numdec > 3:
856+
if numdec > 1:
857857
# Label only bases
858858
self.sublabel = set((1,))
859859
else:
@@ -1857,10 +1857,10 @@ def tick_values(self, vmin, vmax):
18571857

18581858
numdec = math.floor(vmax) - math.ceil(vmin)
18591859

1860-
if self._subs is None: # autosub
1861-
if numdec > 10:
1862-
subs = np.array([1.0])
1863-
elif numdec > 6:
1860+
if self._subs is None: # autosub for minor ticks
1861+
if numdec > 10 or b < 3:
1862+
return np.array([]) # no minor ticks
1863+
elif numdec > 5 and b >= 6:
18641864
subs = np.arange(2.0, b, 2.0)
18651865
else:
18661866
subs = np.arange(2.0, b)

0 commit comments

Comments
 (0)