Skip to content

Commit

Permalink
Merge pull request matplotlib#7594 from efiring/classic_no_minor
Browse files Browse the repository at this point in the history
[MRG+1] LogFormatter bugfix, docs, support classic
  • Loading branch information
dopplershift authored Dec 9, 2016
2 parents 7371b52 + 1706340 commit 1b58fcd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
10 changes: 10 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ the kwarg is None which internally sets it to the 'auto' string,
triggering a new algorithm for adjusting the maximum according
to the axis length relative to the ticklabel font size.

`matplotlib.ticker.LogFormatter` gains minor_thresholds kwarg
-------------------------------------------------------------

Previously, minor ticks on log-scaled axes were not labeled by
default. An algorithm has been added to the
`~matplotlib.ticker.LogFormatter` to control the labeling of
ticks between integer powers of the base. The algorithm uses
two parameters supplied in a kwarg tuple named 'minor_thresholds'.
See the docstring for further explanation.


New defaults for 3D quiver function in mpl_toolkits.mplot3d.axes3d.py
---------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions doc/users/dflt_style_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,15 @@ Z-order
``rcParams['axes.axisbelow'] = False``.


``LogFormatter`` labeling of minor ticks
========================================

Minor ticks on a log axis are now labeled when the axis view limits
span a range less than or equal to the interval between two major
ticks. See `~matplotlib.ticker.LogFormatter` for details. The
minor tick labeling is turned off when using ``mpl.style.use('classic')``,
but cannot be controlled independently via ``rcParams``.


``ScalarFormatter`` tick label formatting with offsets
======================================================
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def set_default_locators_and_formatters(self, axis):
axis.set_minor_locator(LogLocator(self.base, self.subs))
axis.set_minor_formatter(
LogFormatterSciNotation(self.base,
labelOnlyBase=self.subs))
labelOnlyBase=bool(self.subs)))

def get_transform(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _sub_labels(axis, subs=()):
assert_equal(label_test, label_expected)


@cleanup
@cleanup(style='default')
def test_LogFormatter_sublabel():
# test label locator
fig, ax = plt.subplots()
Expand Down
21 changes: 16 additions & 5 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,12 @@ class LogFormatter(Formatter):
major and minor ticks; the tick locations might be set manually,
or by a locator that puts ticks at integer powers of base and
at intermediate locations. For this situation, disable the
minor_thresholds logic by using ``minor_thresholds=(np.inf, np.inf)``.
minor_thresholds logic by using ``minor_thresholds=(np.inf, np.inf)``,
so that all ticks will be labeled.
To disable labeling of minor ticks when 'labelOnlyBase' is False,
use ``minor_thresholds=(0, 0)``. This is the default for the
"classic" style.
Examples
--------
Expand All @@ -848,14 +853,18 @@ class LogFormatter(Formatter):
To label all minor ticks when the view limits span up to 1.5
decades, use ``minor_thresholds=(1.5, 1.5)``.
"""
def __init__(self, base=10.0, labelOnlyBase=False,
minor_thresholds=(1, 0.4),
minor_thresholds=None,
linthresh=None):

self._base = float(base)
self.labelOnlyBase = labelOnlyBase
if minor_thresholds is None:
if rcParams['_internal.classic_mode']:
minor_thresholds = (0, 0)
else:
minor_thresholds = (1, 0.4)
self.minor_thresholds = minor_thresholds
self._sublabels = None
self._linthresh = linthresh
Expand Down Expand Up @@ -896,7 +905,6 @@ def set_locs(self, locs=None):
b = self._base

vmin, vmax = self.axis.get_view_interval()
self.d = abs(vmax - vmin)

# Handle symlog case:
linthresh = self._linthresh
Expand Down Expand Up @@ -939,6 +947,9 @@ def __call__(self, x, pos=None):
"""
Return the format for tick val `x`.
"""
vmin, vmax = self.axis.get_view_interval()
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
d = abs(vmax - vmin)
b = self._base
if x == 0.0:
return '0'
Expand All @@ -959,7 +970,7 @@ def __call__(self, x, pos=None):
elif x < 1:
s = '%1.0e' % x
else:
s = self.pprint_val(x, self.d)
s = self.pprint_val(x, d)
if sign == -1:
s = '-%s' % s

Expand Down

0 comments on commit 1b58fcd

Please sign in to comment.