Skip to content

Commit

Permalink
Fix Plot Geometry Colorfills (#3355)
Browse files Browse the repository at this point in the history
* Fix Plot Geometry Colorfills

* remove uneeded import in test

* update test threshold
  • Loading branch information
kgoebber authored Jan 10, 2024
1 parent 4f0ff3b commit fcd883d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/metpy/plots/declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -1938,12 +1938,12 @@ def _build(self):
else self.label_edgecolor)
self.label_facecolor = (['none'] if self.label_facecolor is None
else self.label_facecolor)
kwargs = self.mpl_args

# Each Shapely object is plotted separately with its corresponding colors and label
for geo_obj, stroke, strokewidth, fill, label, fontcolor, fontoutline in zip(
self.geometry, cycle(self.stroke), cycle(self.stroke_width), cycle(self.fill),
cycle(self.labels), cycle(self.label_facecolor), cycle(self.label_edgecolor)):
kwargs = self.mpl_args.copy()
# Plot the Shapely object with the appropriate method and colors
if isinstance(geo_obj, (MultiPolygon, Polygon)):
kwargs.setdefault('edgecolor', stroke)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions tests/plots/test_declarative.py
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,42 @@ def test_declarative_plot_geometry_lines(ccrs):
return pc.figure


@pytest.mark.mpl_image_compare(remove_text=False, tolerance=0.013)
def test_declarative_plot_geometry_fills(ccrs):
"""Test that `PlotGeometry` correctly plots MultiLineString and LineString objects."""
from shapely.geometry import Polygon

# MultiPolygons and Polygons to plot
mdt_risk_polygon = Polygon(
[(-87.07, 31.68), (-88.65, 30.96), (-91.83, 30.52), (-92.83, 30.82), (-93.18, 31.77),
(-92.65, 33.31), (-92.64, 35.22), (-91.74, 36.16), (-88.84, 35.53), (-86.13, 34.5),
(-85.45, 33.01), (-86, 32.05), (-87.07, 31.68)])
high_risk_polygon = Polygon(
[(-91.88, 32.99), (-89.82, 34.4), (-88.19, 34.21), (-87.72, 33.46), (-88.23, 32.48),
(-90.53, 32), (-91.74, 32.07), (-91.88, 32.99)])

# Plot geometry, set colors and labels
geo = PlotGeometry()
geo.geometry = [mdt_risk_polygon, high_risk_polygon]
geo.fill = ['#E06666', '#EE99EE']
geo.stroke = ['#E06666', '#EE99EE']
geo.labels = None

# Place plot in a panel and container
panel = MapPanel()
panel.area = [-120, -75, 25, 50]
panel.projection = 'lcc'
panel.title = ' '
panel.plots = [geo]

pc = PanelContainer()
pc.size = (12, 12)
pc.panels = [panel]
pc.draw()

return pc.figure


@pytest.mark.mpl_image_compare(remove_text=False, tolerance=1.900)
def test_declarative_plot_geometry_points(ccrs):
"""Test that `PlotGeometry` correctly plots Point and MultiPoint objects."""
Expand Down

0 comments on commit fcd883d

Please sign in to comment.