Skip to content

Commit 2c6f7af

Browse files
committed
Fix autolevels with SymLogNorm when base is not provided
1 parent fe8d70f commit 2c6f7af

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

proplot/axes/plot.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@
3030
from .. import constructor
3131
from ..config import rc
3232
from ..internals import ic # noqa: F401
33-
from ..internals import _dummy_context, _not_none, _state_context, docstring, warnings
33+
from ..internals import (
34+
_dummy_context,
35+
_flexible_getattr,
36+
_not_none,
37+
_state_context,
38+
docstring,
39+
warnings,
40+
)
3441
from ..utils import edges, edges2d, to_rgb, to_xyz, units
3542

3643
try:
@@ -2672,7 +2679,8 @@ def _auto_levels_locator(
26722679
elif isinstance(norm, mcolors.LogNorm):
26732680
level_locator = tick_locator = mticker.LogLocator(**locator_kw)
26742681
elif isinstance(norm, mcolors.SymLogNorm):
2675-
locator_kw.setdefault('linthresh', norm.linthresh)
2682+
locator_kw.setdefault('base', _flexible_getattr(norm, 'base', 10))
2683+
locator_kw.setdefault('linthresh', _flexible_getattr(norm, 'linthresh', 1))
26762684
level_locator = tick_locator = mticker.SymmetricalLogLocator(**locator_kw)
26772685
else:
26782686
nbins = N * 2 if positive or negative else N

proplot/internals/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
ic = lambda *a: None if not a else (a[0] if len(a) == 1 else a) # noqa
1919

2020

21+
def _flexible_getattr(obj, attr, default=None):
22+
"""
23+
Search for attribute ``attr`` and ``_attr``. This guards against simple
24+
upstream matplotlib changes.
25+
"""
26+
if hasattr(obj, attr) and hasattr(obj, '_' + attr):
27+
warnings._warn_proplot(
28+
f"Object {obj!r} has both {attr!r} and {'_' + attr!r} attributes."
29+
'Using former.'
30+
)
31+
return getattr(obj, attr, getattr(obj, '_' + attr, default))
32+
33+
2134
def _not_none(*args, default=None, **kwargs):
2235
"""
2336
Return the first non-``None`` value. This is used with keyword arg aliases and

0 commit comments

Comments
 (0)