Skip to content

Commit

Permalink
Implement optional grid label overlapping check
Browse files Browse the repository at this point in the history
  • Loading branch information
lukelbd committed Jan 23, 2022
1 parent bcf4fde commit 3ff02a3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
20 changes: 19 additions & 1 deletion proplot/axes/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
try:
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import cartopy.mpl.gridliner as cgridliner
from cartopy.crs import Projection
from cartopy.mpl.geoaxes import GeoAxes as _GeoAxes
except ModuleNotFoundError:
ccrs = cfeature = None
ccrs = cfeature = cgridliner = None
_GeoAxes = Projection = object

try:
Expand Down Expand Up @@ -175,6 +176,23 @@
docstring._snippet_manager['geo.format'] = _format_docstring


class _GeoLabel(object):
"""
Optionally omit overlapping check if an rc setting is disabled.
"""
def check_overlapping(self, *args, **kwargs):
if rc['grid.checkoverlap']:
return super().check_overlapping(*args, **kwargs)
else:
return False


# Add monkey patch to gridliner module
if cgridliner is not None and hasattr(cgridliner, 'Label'): # only recent versions
_cls = type('Label', (_GeoLabel, cgridliner.Label), {})
cgridliner.Label = _cls


class _GeoAxis(object):
"""
Dummy axis used by longitude and latitude locators and for storing view limits on
Expand Down
36 changes: 18 additions & 18 deletions proplot/internals/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,58 +1249,59 @@ def copy(self):
"everything. If ``True``, draw them above everything. If ``'line'``, "
'draw them above patches but below lines and markers.'
),
'grid.checkoverlap': (
False,
_validate_bool,
'Whether to have cartopy automatically check for and remove overlapping '
'`~proplot.axes.GeoAxes` gridline labels.'
),
'grid.dmslabels': (
True,
_validate_bool,
'Whether to use degrees-minutes-seconds rather than decimals for gridline '
'labels on cartopy `~proplot.axes.GeoAxes`.'
'Whether to use degrees-minutes-seconds rather than decimals for '
'cartopy `~proplot.axes.GeoAxes` gridlines.'
),
'grid.geolabels': (
True,
_validate_bool,
"Whether to include the ``'geo'`` spine in cartopy >= 0.20 when otherwise "
'toggling left, right, bottom, or top outer labels.'
'toggling left, right, bottom, or top `~proplot.axes.GeoAxes` gridline labels.'
),
'grid.inlinelabels': (
False,
_validate_bool,
'Whether to use inline labels for cartopy `~proplot.axes.GeoAxes` '
'longitude and latitude gridlines.'
'Whether to add inline labels for cartopy `~proplot.axes.GeoAxes` gridlines.'
),
'grid.labels': (
False,
_validate_bool,
'Whether to use outer labels for cartopy and basemap `~proplot.axes.GeoAxes` '
'longitude and latitude gridlines.'
'Whether to add outer labels for `~proplot.axes.GeoAxes` gridlines.'
),
'grid.labelcolor': (
BLACK,
_validate_color,
'Font color for longitude and latitude gridline labels in '
'`~proplot.axes.GeoAxes`.'
'Font color for `~proplot.axes.GeoAxes` gridline labels.'
),
'grid.labelpad': (
GRIDPAD,
_validate_pt,
'Padding between map boundary edge and longitude and '
'latitude labels for `~proplot.axes.GeoAxes`.' + _addendum_pt
'Padding between the map boundary and cartopy `~proplot.axes.GeoAxes` '
'gridline labels.' + _addendum_pt
),
'grid.labelsize': (
SMALLSIZE,
_validate_fontsize,
'Font size for longitude and latitude gridline labels in '
'`~proplot.axes.GeoAxes`.' + _addendum_font
'Font size for `~proplot.axes.GeoAxes` gridline labels.' + _addendum_font
),
'grid.labelweight': (
'normal',
_validate_fontweight,
'Font weight for longitude and latitude gridline labels in '
'`~proplot.axes.GeoAxes`.'
'Font weight for `~proplot.axes.GeoAxes` gridline labels.'
),
'grid.nsteps': (
250,
_validate_int,
'Number of interpolation steps used to draw cartopy gridlines.'
'Number of points used to draw cartopy `~proplot.axes.GeoAxes` gridlines.'
),
'grid.pad': (
GRIDPAD,
Expand All @@ -1310,8 +1311,7 @@ def copy(self):
'grid.rotatelabels': (
False, # False limits projections where labels are available
_validate_bool,
'Whether to rotate longitude and latitude gridline labels for cartopy '
'`~proplot.axes.GeoAxes`.'
'Whether to rotate cartopy `~proplot.axes.GeoAxes` gridline labels.'
),
'grid.style': (
'-',
Expand Down

1 comment on commit 3ff02a3

@L1angY
Copy link

@L1angY L1angY commented on 3ff02a3 Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it need to describe in more detail what "overlapping label" is in a suitable place馃榿馃帀馃帀馃帀馃挅馃挅馃挅

Please sign in to comment.