Skip to content

Commit bf9fc34

Browse files
committed
Misc cleanup
1 parent fa7a6b6 commit bf9fc34

2 files changed

Lines changed: 52 additions & 51 deletions

File tree

proplot/scale.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ class _Scale(object):
7070
"""
7171
def __init__(self, *args, **kwargs):
7272
# Pass a dummy axis to the superclass
73+
# WARNING: Smart bounds is deprecated. Figure out workaround by matplotlib
74+
# 3.4: https://github.com/matplotlib/matplotlib/pull/11004
75+
# Without smart bounds, inverse scale ticks disappear and Mercator ticks
76+
# have weird issues.
7377
axis = type('Axis', (object,), {'axis_name': 'x'})()
7478
super().__init__(axis, *args, **kwargs)
7579
self._default_smart_bounds = None
@@ -196,7 +200,6 @@ def __init__(self, **kwargs):
196200
"""
197201
keys = ('base', 'nonpos', 'subs')
198202
super().__init__(**_parse_logscale_args(*keys, **kwargs))
199-
# self._default_major_formatter = mticker.LogFormatter(self.base)
200203
self._default_major_locator = mticker.LogLocator(self.base)
201204
self._default_minor_locator = mticker.LogLocator(self.base, self.subs)
202205

@@ -241,7 +244,6 @@ def __init__(self, **kwargs):
241244
keys = ('base', 'linthresh', 'linscale', 'subs')
242245
super().__init__(**_parse_logscale_args(*keys, **kwargs))
243246
transform = self.get_transform()
244-
# self._default_major_formatter = mticker.SymmetricalLogFormatter(transform)
245247
self._default_major_locator = mticker.SymmetricalLogLocator(transform)
246248
self._default_minor_locator = mticker.SymmetricalLogLocator(transform, self.subs) # noqa: E501
247249

@@ -364,19 +366,19 @@ def __init__(
364366

365367
# Try to borrow locators and formatters
366368
# WARNING: Using the same locator on multiple axes can evidently
367-
# have unintended side effects! Matplotlib bug. So we make copies.
369+
# have unintended side effects! So we make copies.
368370
for scale in (arg, parent_scale):
369371
if not isinstance(scale, _Scale):
370372
continue
371373
if isinstance(scale, mscale.LinearScale):
372374
continue
373-
for key in (
375+
for name in (
374376
'major_locator', 'minor_locator', 'major_formatter', 'minor_formatter'
375377
):
376-
key = '_default_' + key
377-
attr = getattr(scale, key)
378-
if getattr(self, key) is None and attr is not None:
379-
setattr(self, key, copy.copy(attr))
378+
attr = f'_default_{name}'
379+
obj = getattr(scale, attr)
380+
if getattr(self, attr) is None and obj is not None:
381+
setattr(self, attr, copy.copy(obj))
380382

381383

382384
class FuncTransform(mtransforms.Transform):
@@ -865,7 +867,6 @@ def __init__(self):
865867
"""""" # empty docstring
866868
super().__init__()
867869
self._transform = InverseTransform()
868-
# self._default_major_formatter = Formatter('log')
869870
self._default_major_locator = mticker.LogLocator(10)
870871
self._default_minor_locator = mticker.LogLocator(10, np.arange(1, 10))
871872
self._default_smart_bounds = True
@@ -876,7 +877,7 @@ def limit_range_for_scale(self, vmin, vmax, minpos):
876877
"""
877878
# Unlike log-scale, we can't just warp the space between
878879
# the axis limits -- have to actually change axis limits. Also this
879-
# scale will invert and swap the limits you provide. Weird!
880+
# scale will invert and swap the limits you provide.
880881
return max(vmin, minpos), max(vmax, minpos)
881882

882883

proplot/ticker.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
docstring.snippets['formatter.params'] = """
3434
zerotrim : bool, optional
35-
Whether to trim trailing zeros. Default is :rc:`axes.formatter.zerotrim`.
35+
Whether to trim trailing zeros. Default is :rc:`formatter.zerotrim`.
3636
tickrange : (float, float), optional
3737
Range within which major tick marks are labelled. Default is ``(-np.inf, np.inf)``.
3838
wraprange : (float, float), optional
@@ -47,41 +47,6 @@
4747
"""
4848

4949

50-
class _GeoFormatter(object):
51-
"""
52-
Mixin class that fixes cartopy formatters.
53-
"""
54-
# NOTE: Cartopy formatters pre 0.18 required axis, and *always* translated
55-
# input values from map projection coordinates to Plate Carrée coordinates.
56-
# After 0.18 you can avoid this behavior by not setting axis but really
57-
# dislike that inconsistency. Solution is temporarily change projection.
58-
def __init__(self, *args, **kwargs):
59-
import cartopy # noqa: F401 (ensure available)
60-
super().__init__(*args, **kwargs)
61-
62-
def __call__(self, value, pos=None):
63-
if self.axis is not None:
64-
context = _set_state(self.axis.axes, projection=ccrs.PlateCarree())
65-
else:
66-
context = _dummy_context()
67-
with context:
68-
return super().__call__(value, pos)
69-
70-
71-
class _LongitudeFormatter(_GeoFormatter, LongitudeFormatter):
72-
"""
73-
Mix longitude formatter with custom formatter.
74-
"""
75-
pass
76-
77-
78-
class _LatitudeFormatter(_GeoFormatter, LatitudeFormatter):
79-
"""
80-
Mix latitude formatter with custom formatter.
81-
"""
82-
pass
83-
84-
8550
class _GeoLocator(mticker.MaxNLocator):
8651
"""
8752
A locator for determining longitude and latitude gridlines.
@@ -169,6 +134,41 @@ def _raw_ticks(self, vmin, vmax):
169134
return [t for t in ticks if -90 <= t <= 90]
170135

171136

137+
class _GeoFormatter(object):
138+
"""
139+
Mixin class that fixes cartopy formatters.
140+
"""
141+
# NOTE: Cartopy formatters pre 0.18 required axis, and *always* translated
142+
# input values from map projection coordinates to Plate Carrée coordinates.
143+
# After 0.18 you can avoid this behavior by not setting axis but really
144+
# dislike that inconsistency. Solution is temporarily change projection.
145+
def __init__(self, *args, **kwargs):
146+
import cartopy # noqa: F401 (ensure available)
147+
super().__init__(*args, **kwargs)
148+
149+
def __call__(self, value, pos=None):
150+
if self.axis is not None:
151+
context = _set_state(self.axis.axes, projection=ccrs.PlateCarree())
152+
else:
153+
context = _dummy_context()
154+
with context:
155+
return super().__call__(value, pos)
156+
157+
158+
class _LongitudeFormatter(_GeoFormatter, LongitudeFormatter):
159+
"""
160+
Mix longitude formatter with custom formatter.
161+
"""
162+
pass
163+
164+
165+
class _LatitudeFormatter(_GeoFormatter, LatitudeFormatter):
166+
"""
167+
Mix latitude formatter with custom formatter.
168+
"""
169+
pass
170+
171+
172172
class AutoFormatter(mticker.ScalarFormatter):
173173
"""
174174
The new default formatter. Differs from `~matplotlib.ticker.ScalarFormatter`
@@ -207,7 +207,7 @@ def __init__(
207207
tickrange = tickrange or (-np.inf, np.inf)
208208
super().__init__(**kwargs)
209209
from .config import rc
210-
zerotrim = _not_none(zerotrim, rc['axes.formatter.zerotrim'])
210+
zerotrim = _not_none(zerotrim, rc['formatter.zerotrim'])
211211
self._zerotrim = zerotrim
212212
self._tickrange = tickrange
213213
self._wraprange = wraprange
@@ -307,7 +307,7 @@ def _get_decimal_point(self, use_locale=None):
307307
"""
308308
from .config import rc
309309
use_locale = _not_none(
310-
use_locale, self.get_useLocale(), rc['axes.formatter.use_locale']
310+
use_locale, self.get_useLocale(), rc['formatter.use_locale']
311311
)
312312
return locale.localeconv()['decimal_point'] if use_locale else '.'
313313

@@ -317,7 +317,7 @@ def _get_default_decimal_point(use_locale=None):
317317
Get decimal point symbol for current locale. Called externally.
318318
"""
319319
from .config import rc
320-
use_locale = _not_none(use_locale, rc['axes.formatter.use_locale'])
320+
use_locale = _not_none(use_locale, rc['formatter.use_locale'])
321321
return locale.localeconv()['decimal_point'] if use_locale else '.'
322322

323323
@staticmethod
@@ -397,7 +397,7 @@ def SigFigFormatter(sigfig=1, zerotrim=None):
397397
Whether to trim trailing zeros.
398398
"""
399399
from .config import rc
400-
zerotrim = _not_none(zerotrim, rc['axes.formatter.zerotrim'])
400+
zerotrim = _not_none(zerotrim, rc['formatter.zerotrim'])
401401

402402
def func(x, pos):
403403
# Limit digits to significant figures
@@ -438,7 +438,7 @@ def SimpleFormatter(
438438
%(formatter.params)s
439439
"""
440440
from .config import rc
441-
zerotrim = _not_none(zerotrim, rc['axes.formatter.zerotrim'])
441+
zerotrim = _not_none(zerotrim, rc['formatter.zerotrim'])
442442
tickrange = tickrange or (-np.inf, np.inf)
443443
prefix = prefix or ''
444444
suffix = suffix or ''

0 commit comments

Comments
 (0)