Skip to content

Commit d800d87

Browse files
gautehCopilot
andcommitted
fix: use draw_labels=['left', 'bottom'] instead of post-setting top_labels
Setting gl.top_labels = None after calling ax.gridlines(draw_labels=True) is invalid in newer Cartopy (only bool/list/str are accepted) and caused blank plots. Use the Cartopy draw_labels list API introduced in Cartopy 0.20 to request labels only on left and bottom sides directly, removing the need for post-hoc patching and the workarounds for Bbox.union errors. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f0b3573 commit d800d87

1 file changed

Lines changed: 1 addition & 24 deletions

File tree

opendrift/models/basemodel/__init__.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,30 +2612,7 @@ def set_up_map(self,
26122612
lonmax -= .1 # To avoid problem with Cartopy
26132613
ax.set_extent([lonmin, lonmax, latmin, latmax], crs=self.crs_lonlat)
26142614

2615-
gl = ax.gridlines(self.crs_lonlat, draw_labels=True, xlocs=xlocs, ylocs=ylocs)
2616-
gl.top_labels = None
2617-
2618-
# Cartopy's _draw_gridliner can fail with Shapely 2.x when the map
2619-
# boundary path is not a closed ring. Wrap it so rendering never
2620-
# crashes, even on older Cartopy builds.
2621-
_original_draw_gridliner = gl._draw_gridliner
2622-
def _safe_draw_gridliner(*args, **kwargs):
2623-
try:
2624-
return _original_draw_gridliner(*args, **kwargs)
2625-
except Exception:
2626-
pass
2627-
gl._draw_gridliner = _safe_draw_gridliner
2628-
2629-
# Cartopy's gridliner.get_tightbbox can raise AttributeError when label
2630-
# artists have no bbox (e.g. after _draw_gridliner silently failed).
2631-
# Returning None is valid for matplotlib – it means "no visible bbox".
2632-
_original_get_tightbbox = gl.get_tightbbox
2633-
def _safe_get_tightbbox(*args, **kwargs):
2634-
try:
2635-
return _original_get_tightbbox(*args, **kwargs)
2636-
except (AttributeError, ValueError):
2637-
return None
2638-
gl.get_tightbbox = _safe_get_tightbbox
2615+
gl = ax.gridlines(self.crs_lonlat, draw_labels=['left', 'bottom'], xlocs=xlocs, ylocs=ylocs)
26392616

26402617
if 'ocean_color' in kwargs:
26412618
ax.patch.set_facecolor(kwargs['ocean_color'])

0 commit comments

Comments
 (0)