Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: ensure Gridliner is up-to-date for title adjustment #2393

Merged
merged 1 commit into from
Jun 8, 2024
Merged
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
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