Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1706340

Browse filesBrowse files
committed
LogFormatter bugfix, docs, support classic
Closes #7590. Classic style, with no minor tick labeling on a log axis, is supported via rcParams['_internal.classic'] LogFormatter changes are documented in api_changes and dflt_style_changes. An implicit boolean is made explicit in scale.py. A LogFormatter attribute that was sometimes, but not always, set by set_locs, but used only in __call__, is replaced by a local variable calculated in __call__. (set_locs doesn't have to be called prior to __call__, so this would have been a bug even if the attribute were always calculated by set_locs.)
1 parent 1c1fd38 commit 1706340
Copy full SHA for 1706340

File tree

Expand file treeCollapse file tree

5 files changed

+37
-7
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+37
-7
lines changed

‎doc/api/api_changes.rst

Copy file name to clipboardExpand all lines: doc/api/api_changes.rst
+10Lines 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

Copy file name to clipboardExpand all lines: doc/users/dflt_style_changes.rst
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,15 @@ Z-order
10421042
``rcParams['axes.axisbelow'] = False``.
10431043

10441044

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

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

‎lib/matplotlib/scale.py

Copy file name to clipboardExpand all lines: lib/matplotlib/scale.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+1-1Lines changed: 1 addition & 1 deletion
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

Copy file name to clipboardExpand all lines: lib/matplotlib/ticker.py
+16-5Lines 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
@@ -937,6 +945,9 @@ def __call__(self, x, pos=None):
937945
"""
938946
Return the format for tick val `x`.
939947
"""
948+
vmin, vmax = self.axis.get_view_interval()
949+
vmin, vmax = mtransforms.nonsingular(vmin, vmax, expander=0.05)
950+
d = abs(vmax - vmin)
940951
b = self._base
941952
if x == 0.0:
942953
return '0'
@@ -957,7 +968,7 @@ def __call__(self, x, pos=None):
957968
elif x < 1:
958969
s = '%1.0e' % x
959970
else:
960-
s = self.pprint_val(x, self.d)
971+
s = self.pprint_val(x, d)
961972
if sign == -1:
962973
s = '-%s' % s
963974

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.