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

Skip to content

Commit 4d692d8

Browse files
authored
Merge pull request #7419 from efiring/log_formatting
ENH: restore default ability to label some minor log ticks.
2 parents 41f4e37 + 129a32b commit 4d692d8

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

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)