Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/pylab_examples/log_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
11 changes: 7 additions & 4 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2 cents is that we are trying to be too smart here and it has unintended consequences for anyone trying to use this formatter. At most, this sublabel filtering should be disabled by default (and possibly activated internally).

Also, the sublabel should probably (if kept) be private.

# Label only bases
self.sublabel = set((1,))
else:
Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should add a comment why no minor ticks should be label when 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)
Expand Down