Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/metpy/plots/_mpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 5 additions & 2 deletions src/metpy/plots/cartopy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
10 changes: 7 additions & 3 deletions src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -733,14 +733,18 @@ 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):
area = _areas[self.area.lower()]
# 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:
Expand Down