Skip to content

Commit fcd883d

Browse files
authored
Fix Plot Geometry Colorfills (#3355)
* Fix Plot Geometry Colorfills * remove uneeded import in test * update test threshold
1 parent 4f0ff3b commit fcd883d

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/metpy/plots/declarative.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1938,12 +1938,12 @@ def _build(self):
19381938
else self.label_edgecolor)
19391939
self.label_facecolor = (['none'] if self.label_facecolor is None
19401940
else self.label_facecolor)
1941-
kwargs = self.mpl_args
19421941

19431942
# Each Shapely object is plotted separately with its corresponding colors and label
19441943
for geo_obj, stroke, strokewidth, fill, label, fontcolor, fontoutline in zip(
19451944
self.geometry, cycle(self.stroke), cycle(self.stroke_width), cycle(self.fill),
19461945
cycle(self.labels), cycle(self.label_facecolor), cycle(self.label_edgecolor)):
1946+
kwargs = self.mpl_args.copy()
19471947
# Plot the Shapely object with the appropriate method and colors
19481948
if isinstance(geo_obj, (MultiPolygon, Polygon)):
19491949
kwargs.setdefault('edgecolor', stroke)
73.6 KB
Loading

tests/plots/test_declarative.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,42 @@ def test_declarative_plot_geometry_lines(ccrs):
21332133
return pc.figure
21342134

21352135

2136+
@pytest.mark.mpl_image_compare(remove_text=False, tolerance=0.013)
2137+
def test_declarative_plot_geometry_fills(ccrs):
2138+
"""Test that `PlotGeometry` correctly plots MultiLineString and LineString objects."""
2139+
from shapely.geometry import Polygon
2140+
2141+
# MultiPolygons and Polygons to plot
2142+
mdt_risk_polygon = Polygon(
2143+
[(-87.07, 31.68), (-88.65, 30.96), (-91.83, 30.52), (-92.83, 30.82), (-93.18, 31.77),
2144+
(-92.65, 33.31), (-92.64, 35.22), (-91.74, 36.16), (-88.84, 35.53), (-86.13, 34.5),
2145+
(-85.45, 33.01), (-86, 32.05), (-87.07, 31.68)])
2146+
high_risk_polygon = Polygon(
2147+
[(-91.88, 32.99), (-89.82, 34.4), (-88.19, 34.21), (-87.72, 33.46), (-88.23, 32.48),
2148+
(-90.53, 32), (-91.74, 32.07), (-91.88, 32.99)])
2149+
2150+
# Plot geometry, set colors and labels
2151+
geo = PlotGeometry()
2152+
geo.geometry = [mdt_risk_polygon, high_risk_polygon]
2153+
geo.fill = ['#E06666', '#EE99EE']
2154+
geo.stroke = ['#E06666', '#EE99EE']
2155+
geo.labels = None
2156+
2157+
# Place plot in a panel and container
2158+
panel = MapPanel()
2159+
panel.area = [-120, -75, 25, 50]
2160+
panel.projection = 'lcc'
2161+
panel.title = ' '
2162+
panel.plots = [geo]
2163+
2164+
pc = PanelContainer()
2165+
pc.size = (12, 12)
2166+
pc.panels = [panel]
2167+
pc.draw()
2168+
2169+
return pc.figure
2170+
2171+
21362172
@pytest.mark.mpl_image_compare(remove_text=False, tolerance=1.900)
21372173
def test_declarative_plot_geometry_points(ccrs):
21382174
"""Test that `PlotGeometry` correctly plots Point and MultiPoint objects."""

0 commit comments

Comments
 (0)