Skip to content

Commit 2ac4071

Browse files
committed
Cleanup + fix cartopy 0.20 issue toggling labels
1 parent b82e315 commit 2ac4071

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

proplot/axes/geo.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,11 @@ def format(
562562

563563
# Initiate context block
564564
rc_kw, rc_mode = _pop_rc(kwargs)
565+
lonlabels = _not_none(lonlabels, labels)
566+
latlabels = _not_none(latlabels, labels)
567+
if '0.18' <= _version_cartopy < '0.20':
568+
lonlabels = _not_none(lonlabels, loninline, inlinelabels)
569+
latlabels = _not_none(latlabels, latinline, inlinelabels)
565570
labelcolor = _not_none(labelcolor, kwargs.get('color', None))
566571
if labelcolor is not None:
567572
rc_kw['grid.labelcolor'] = labelcolor
@@ -581,9 +586,6 @@ def format(
581586
labels = _not_none(labels, rc.find('grid.labels', context=True))
582587
lonlabels = _not_none(lonlabels, labels)
583588
latlabels = _not_none(latlabels, labels)
584-
if '0.18' <= _version_cartopy < '0.20':
585-
lonlabels = _not_none(lonlabels, loninline, inlinelabels)
586-
latlabels = _not_none(latlabels, latinline, inlinelabels)
587589
lonarray = self._to_label_array(lonlabels, lon=True)
588590
latarray = self._to_label_array(latlabels, lon=False)
589591

@@ -1070,8 +1072,6 @@ def _update_major_gridlines(
10701072
# Update gridline label parameters
10711073
# NOTE: Cartopy 0.18 and 0.19 can not draw both edge and inline labels. Instead
10721074
# requires both a set 'side' and 'x_inline' is True (applied in GeoAxes.format).
1073-
# NOTE: Cartopy 0.20 uses 'x' or 'y' as value for 'inline_labels' sometimes but
1074-
# only ever checks their boolean values. Simply use boolean toggles for now.
10751075
# NOTE: The 'xpadding' and 'ypadding' props were introduced in v0.16
10761076
# with default 5 points, then set to default None in v0.18.
10771077
# TODO: Cartopy has had two formatters for a while but we use the newer one.
@@ -1085,7 +1085,9 @@ def _update_major_gridlines(
10851085
if rotatelabels is not None:
10861086
gl.rotate_labels = bool(rotatelabels) # ignored in cartopy < 0.18
10871087
if latinline is not None or loninline is not None:
1088-
gl.inline_labels = loninline or latinline # ignored in cartopy < 0.20
1088+
lon, lat = loninline, latinline
1089+
b = True if lon and lat else 'x' if lon else 'y' if lat else None
1090+
gl.inline_labels = b # ignored in cartopy < 0.20
10891091

10901092
# Gridline label toggling
10911093
# Issue warning instead of error!
@@ -1105,10 +1107,11 @@ def _update_major_gridlines(
11051107
f'{type(self.projection).__name__} projection.'
11061108
)
11071109
lonarray = [False] * 5
1108-
print(latarray, lonarray)
1109-
self._toggle_gridliner_labels(
1110-
gl, *latarray[:2], *lonarray[2:4], latarray[4] or lonarray[4]
1111-
)
1110+
array = [
1111+
True if lon and lat else 'x' if lon else 'y' if lat else False
1112+
for lon, lat in zip(lonarray, latarray)
1113+
]
1114+
self._toggle_gridliner_labels(gl, *array[:2], *array[2:4], array[4])
11121115

11131116
def _update_minor_gridlines(self, longrid=None, latgrid=None, nsteps=None):
11141117
"""

0 commit comments

Comments
 (0)