8000 Merge pull request #7594 from efiring/classic_no_minor · matplotlib/matplotlib@1b58fcd · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b58fcd

Browse files
authored
Merge pull request #7594 from efiring/classic_no_minor
[MRG+1] LogFormatter bugfix, docs, support classic
2 parents 7371b52 + 1706340 commit 1b58fcd

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

doc/api/api_changes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ the kwarg is None which internally sets it to the 'auto' string,
141141
triggering a new algorithm for adjusting the maximum according
142142
to the axis length relative to the ticklabel font size.
143143

144+
`matplotlib.ticker.LogFormatter` gains minor_thresholds kwarg
145+
-------------------------------------------------------------
146+
147+
Previously, minor ticks on log-scaled axes were not labeled by
148+
default. An algorithm has been added to the
149+
`~matplotlib.ticker.LogFormatter` to control the labeling of
150+
ticks between integer powers of the base. The algorithm uses
151+
two parameters supplied in a kwarg tuple named 'minor_thresholds'.
152+
See the docstring for further explanation.
153+
144154

145155
New defaults for 3D quiver function in mpl_toolkits.mplot3d.axes3d.py
146156
---------------------------------------------------------------------

doc/users/dflt_style_changes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,15 @@ Z-order
10431043
``rcParams['axes.axisbelow'] = False``.
10441044

10451045

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

10471056
``ScalarFormatter`` tick label formatting with offsets
10481057
======================================================

lib/matplotlib/scale.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def set_default_locators_and_formatters(self, axis):
251251
axis.set_minor_locator(LogLocator(self.base, self.subs))
252252
axis.set_minor_formatter(
253253
LogFormatterSciNotation(self.base,
254-
labelOnlyBase=self.subs))
254+
labelOnlyBase=bool(self.subs)))
255255

256256
def get_transform(self):
257257
"""

lib/matplotlib/tests/test_ticker.py

Lines changed: 1 addition & 1 deletion
8000
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def _sub_labels(axis, subs=()):
231231
assert_equal(label_test, label_expected)
232232

233233

234-
@cleanup
234+
@cleanup(style='default')
235235
def test_LogFormatter_sublabel():
236236
# test label locator
237237
fig, ax = plt.subplots()

lib/matplotlib/ticker.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,12 @@ class LogFormatter(Formatter):
837837
major and minor ticks; the tick locations might be set manually,
838838
or by a locator that puts ticks at integer powers of base and
839839
at intermediate locations. For this situation, disable the
840-
minor_thresholds logic by using ``minor_thresholds=(np.inf, np.inf)``.
840+
minor_thresholds logic by using ``minor_thresholds=(np.inf, np.inf)``,
841+
so that all ticks will be labeled.
842+
843+
To disable labeling of minor ticks when 'labelOnlyBase' is False,
844+
use ``minor_thresholds=(0, 0)``. This is the default for the
845+
"classic" style.
841846
842847
Examples
843848
--------
@@ -848,14 +853,18 @@ class LogFormatter(Formatter):
848853
To label all minor ticks when the view limits span up to 1.5
849854
decades, use ``minor_thresholds=(1.5, 1.5)``.
850855
851-
852856
"""
853857
def __init__(self, base=10.0, labelOnlyBase=False,
854-
minor_thresholds=(1, 0.4),
858+
minor_thresholds=None,
855859
linthresh=None):
856860

857861
self._base = float(base)
858862
self.labelOnlyBase = labelOnlyBase
863+
if minor_thresholds is None:
864+
if rcParams['_internal.classic_mode']:
865+
minor_thresholds = (0, 0)
866+
else:
867+
minor_thresholds = (1, 0.4)
859868
self.minor_thresholds = minor_thresholds
860869
self._sublabels = None
861870
self._linthresh = linthresh
@@ -896,7 +905,6 @@ def set_locs(self, locs=None):
896905
b = self._base
897906

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

901909
# Handle symlog case:
902910
linthresh = self._linthresh
@@ -939,6 +947,9 @@ def __call__(self, x, pos=None):
939947
"""
940948
Return the format for tick val `x`.
941949
"""
950+
vmin, vmax = self.axis.get_view_interval()
951+
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
952+
d = abs(vmax - vmin)
942953
b = self._base
943954
if x == 0.0:
944955
return '0'
@@ -959,7 +970,7 @@ def __call__(self, x, pos=None):
959970
elif x < 1:
960971
s = '%1.0e' % x
961972
else:
962-
s = self.pprint_val(x, self.d)
973+
s = self.pprint_val(x, d)
963974
if sign == -1:
964975
s = '-%s' % s
965976

0 commit comments

Comments
 (0)
0