From 5e6fd9e9beabe789b2308df2c0bc40522d3b768e Mon Sep 17 00:00:00 2001 From: kgoebber Date: Tue, 5 May 2020 08:28:02 -0500 Subject: [PATCH 1/2] updates for cartopy 0.18 --- src/metpy/plots/cartopy_utils.py | 7 +++++-- src/metpy/plots/declarative.py | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/metpy/plots/cartopy_utils.py b/src/metpy/plots/cartopy_utils.py index 0140946f990..2af3515d2ca 100644 --- a/src/metpy/plots/cartopy_utils.py +++ b/src/metpy/plots/cartopy_utils.py @@ -3,17 +3,20 @@ # SPDX-License-Identifier: BSD-3-Clause """Cartopy specific mapping utilities.""" +import cartopy.crs as ccrs import cartopy.feature as cfeature from ..cbook import get_test_data -class MetPyMapFeature(cfeature.NaturalEarthFeature): +class MetPyMapFeature(cfeature.Feature): """A simple interface to US County shapefiles.""" def __init__(self, name, scale, **kwargs): """Create USCountiesFeature instance.""" - super().__init__('', name, scale, **kwargs) + super().__init__(ccrs.PlateCarree(), **kwargs) + self.name = name + self.scale = scale def geometries(self): """Return an iterator of (shapely) geometries for this feature.""" diff --git a/src/metpy/plots/declarative.py b/src/metpy/plots/declarative.py index b60c4654445..1ea5b3a2e2c 100644 --- a/src/metpy/plots/declarative.py +++ b/src/metpy/plots/declarative.py @@ -479,7 +479,7 @@ def lookup_projection(projection_code): return projections[projection_code] -def lookup_map_feature(feature_name): +def lookup_map_feature(feature_name, area): """Get a Cartopy map feature based on a name.""" import cartopy.feature as cfeature from . import cartopy_utils @@ -491,7 +491,7 @@ def lookup_map_feature(feature_name): except AttributeError: feat = getattr(cartopy_utils, name) scaler = cfeature.AdaptiveScaler('20m', (('5m', 5), ('500k', 1))) - return feat.with_scale(scaler) + return feat.with_scale(scaler.scale_from_extent(area)) class Panel(HasTraits): @@ -685,7 +685,7 @@ def _layer_features(self): """ for item in self.layers: if isinstance(item, str): - feat = lookup_map_feature(item) + feat = lookup_map_feature(item, self.feature_area) else: feat = item @@ -733,6 +733,7 @@ def draw(self): # Set the extent as appropriate based on the area. One special case for 'global' if self.area == 'global': self.ax.set_global() + self.feature_area = [-180, 180, 90, -90] elif self.area is not None: # Try to look up if we have a string if isinstance(self.area, str): @@ -740,7 +741,10 @@ def draw(self): # Otherwise, assume we have a tuple to use as the extent else: area = self.area + self.feature_area = area self.ax.set_extent(area, DEFAULT_LAT_LON) + else: + self.feature_area = None # Draw all of the plots. for p in self.plots: From ab4ebeadbde308ccad3add3bcf732be19d23e3dc Mon Sep 17 00:00:00 2001 From: kgoebber Date: Mon, 11 May 2020 16:00:21 -0500 Subject: [PATCH 2/2] fix clipping of text plots --- src/metpy/plots/_mpl.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/metpy/plots/_mpl.py b/src/metpy/plots/_mpl.py index a65b246bcc7..abcac34034f 100644 --- a/src/metpy/plots/_mpl.py +++ b/src/metpy/plots/_mpl.py @@ -102,6 +102,9 @@ def scattertext(self, x, y, texts, loc=(0, 0), **kw): self.add_artist(text_obj) self.update_datalim(text_obj.get_datalim(self.transData)) self.autoscale_view() + + # Update the clipbox based on bbox + text_obj.clipbox = self.bbox return text_obj class TextCollection(Text):