Skip to content

Commit

Permalink
Merge pull request #2393 from rcomer/gl-titles
Browse files Browse the repository at this point in the history
FIX: ensure Gridliner is up-to-date for title adjustment
  • Loading branch information
greglucas committed Jun 8, 2024
2 parents 17c7ef8 + 7a88b84 commit 11c0c4c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,10 @@ def _update_title_position(self, renderer):
# Get the max ymax of all top labels
top = -1
for gl in gridliners:
if gl.has_labels():
# Both top and geo labels can appear at the top of the axes
# Both top and geo labels can appear at the top of the axes
if gl.top_labels or gl.geo_labels:
# Make sure Gridliner is populated and up-to-date
gl._draw_gridliner(renderer=renderer)
for label in (gl.top_label_artists +
gl.geo_label_artists):
bb = label.get_tightbbox(renderer)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,20 @@ def test_gridliner_title_noadjust():
assert ax.title.get_position() == pos


def test_gridliner_title_adjust_no_layout_engine():
fig = plt.figure()
ax = fig.add_subplot(projection=ccrs.PlateCarree())
gl = ax.gridlines(draw_labels=True)
title = ax.set_title("MY TITLE")

# After first draw, title should be above top labels.
fig.draw_without_rendering()
max_label_y = max([bb.get_tightbbox().ymax for bb in gl.top_label_artists])
min_title_y = title.get_tightbbox().ymin

assert min_title_y > max_label_y


def test_gridliner_labels_zoom():
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
Expand Down

0 comments on commit 11c0c4c

Please sign in to comment.