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: gridliner auto-updates by default (and always in future) #2330

Merged
merged 1 commit into from
Feb 23, 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
10 changes: 7 additions & 3 deletions lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,7 @@ def gridlines(self, crs=None, draw_labels=False,
xformatter=None, yformatter=None, xlim=None, ylim=None,
rotate_labels=None, xlabel_style=None, ylabel_style=None,
labels_bbox_style=None, xpadding=5, ypadding=5,
offset_angle=25, auto_update=False, formatter_kwargs=None,
offset_angle=25, auto_update=None, formatter_kwargs=None,
**kwargs):
"""
Automatically add gridlines to the axes, in the given coordinate
Expand Down Expand Up @@ -1464,9 +1464,13 @@ def gridlines(self, crs=None, draw_labels=False,
a label must be flipped to be more readable.
For example, a value of 10 makes a vertical top label to be
flipped only at 100 degrees.
auto_update: bool
Whether to update the grilines and labels when the plot is
auto_update: bool, default=True
Whether to update the gridlines and labels when the plot is
refreshed.

.. deprecated:: 0.23
In future the gridlines and labels will always be updated.

formatter_kwargs: dict, optional
Options passed to the default formatters.
See :class:`~cartopy.mpl.ticker.LongitudeFormatter` and
Expand Down
15 changes: 13 additions & 2 deletions lib/cartopy/mpl/gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def __init__(self, axes, crs, draw_labels=False, xlocator=None,
xlim=None, ylim=None, rotate_labels=None,
xlabel_style=None, ylabel_style=None, labels_bbox_style=None,
xpadding=5, ypadding=5, offset_angle=25,
auto_update=False, formatter_kwargs=None):
auto_update=None, formatter_kwargs=None):
"""
Artist used by :meth:`cartopy.mpl.geoaxes.GeoAxes.gridlines`
to add gridlines and tick labels to a map.
Expand Down Expand Up @@ -218,9 +218,13 @@ def __init__(self, axes, crs, draw_labels=False, xlocator=None,
a label must be flipped to be more readable.
For example, a value of 10 makes a vertical top label to be
flipped only at 100 degrees.
auto_update: bool
auto_update: bool, default=True
Whether to redraw the gridlines and labels when the figure is
updated.

.. deprecated:: 0.23
In future the gridlines and labels will always be redrawn.

formatter_kwargs: dict, optional
Options passed to the default formatters.
See :class:`~cartopy.mpl.ticker.LongitudeFormatter` and
Expand Down Expand Up @@ -444,6 +448,13 @@ def __init__(self, axes, crs, draw_labels=False, xlocator=None,

# Draw status
self._drawn = False
if auto_update is None:
auto_update = True
else:
warnings.warn(
"The auto_update parameter was deprecated at Cartopy 0.23. In future "
"the gridlines and labels will always be updated.",
DeprecationWarning)
self._auto_update = auto_update

def has_labels(self):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 5 additions & 6 deletions lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_grid_labels():
@pytest.mark.skipif(geos_version == (3, 9, 0), reason="GEOS intersection bug")
@pytest.mark.natural_earth
@pytest.mark.mpl_image_compare(filename='gridliner_labels_tight.png',
tolerance=2.92)
tolerance=2.9)
def test_grid_labels_tight():
# Ensure tight layout accounts for gridlines
fig = plt.figure(figsize=(7, 5))
Expand Down Expand Up @@ -290,8 +290,7 @@ def test_gridliner_constrained_adjust_datalim():
ax.autoscale()

# Add some gridlines
ax.gridlines(draw_labels=["bottom", "left"], auto_update=True,
linestyle="-")
ax.gridlines(draw_labels=["bottom", "left"], linestyle="-")

return fig

Expand Down Expand Up @@ -515,11 +514,11 @@ def test_gridliner_remove():


def test_gridliner_save_tight_bbox():
# Smoke test for save with auto_update=True and bbox_inches=Tight (gh2246).
# Smoke test for save with bbox_inches=Tight (gh2246).
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_global()
ax.gridlines(draw_labels=True, auto_update=True)
ax.gridlines(draw_labels=True)
fig.savefig(io.BytesIO(), bbox_inches='tight')


Expand Down Expand Up @@ -569,7 +568,7 @@ def test_gridliner_labels_zoom():

# Start with a global map.
ax.set_global()
gl = ax.gridlines(draw_labels=True, auto_update=True)
gl = ax.gridlines(draw_labels=True)

fig.draw_without_rendering() # Generate child artists
labels = [a.get_text() for a in gl.bottom_label_artists if a.get_visible()]
Expand Down