Skip to content

Commit bf40fcd

Browse files
committed
Fix shared GeoAxes zoom not propagating to sibling subplots
1 parent 1f15ef0 commit bf40fcd

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

lib/cartopy/mpl/geoaxes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ def _draw_preprocess(self):
459459
# then we should autoscale the view.
460460
if self.get_autoscale_on() and self.ignore_existing_data_limits:
461461
self.autoscale_view()
462+
self.ignore_existing_data_limits = False
462463

463464
# apply_aspect may change the x or y data limits, so must be called
464465
# before the patch is updated.
@@ -564,6 +565,8 @@ def __clear(self):
564565

565566
self.dataLim.intervalx = self.projection.x_limits
566567
self.dataLim.intervaly = self.projection.y_limits
568+
self.viewLim.intervalx = self.projection.x_limits
569+
self.viewLim.intervaly = self.projection.y_limits
567570

568571
def clear(self):
569572
"""Clear the current Axes and add boundary lines."""
@@ -747,10 +750,7 @@ def get_extent(self, crs=None):
747750

748751
def _get_extent_geom(self, crs=None):
749752
# Perform the calculations for get_extent(), which just repackages it.
750-
with self.hold_limits():
751-
if self.get_autoscale_on():
752-
self.autoscale_view()
753-
[x1, y1], [x2, y2] = self.viewLim.get_points()
753+
[x1, y1], [x2, y2] = self.viewLim.get_points()
754754

755755
domain_in_src_proj = sgeom.Polygon([[x1, y1], [x2, y1],
756756
[x2, y2], [x1, y2],

lib/cartopy/tests/mpl/test_axes.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,26 @@ def test_geoaxes_set_boundary_clipping():
154154
transform=ax1.transAxes)
155155

156156
return fig
157+
158+
159+
def test_shared_axes_zoom_propagation():
160+
fig = plt.figure()
161+
proj = ccrs.PlateCarree()
162+
ax1 = fig.add_subplot(1, 2, 1, projection=proj)
163+
ax2 = fig.add_subplot(1, 2, 2, projection=proj,
164+
sharex=ax1, sharey=ax1)
165+
166+
fig.draw_without_rendering()
167+
168+
# Simulate interactive zoom tool behavior:
169+
# set_xbound/set_ybound use auto=None (no-op for autoscale)
170+
# set_autoscalex/y_on(False) only affects the calling axes
171+
ax1.set_xbound(-20, 20)
172+
ax1.set_autoscalex_on(False)
173+
ax1.set_ybound(-10, 10)
174+
ax1.set_autoscaley_on(False)
175+
176+
fig.draw_without_rendering()
177+
178+
assert ax2.get_xlim() == (-20, 20)
179+
assert ax2.get_ylim() == (-10, 10)

lib/cartopy/tests/mpl/test_set_extent.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ def test_view_lim_autoscaling():
148148
expected_non_tight, decimal=1)
149149

150150

151-
def test_view_lim_default_global(tmp_path):
151+
def test_view_lim_default_global():
152152
ax = plt.axes(projection=ccrs.PlateCarree())
153-
# The view lim should be the default unit bbox until it is drawn.
154-
assert_array_almost_equal(ax.viewLim.frozen().get_points(),
155-
[[0, 0], [1, 1]])
156-
plt.savefig(tmp_path / 'view_lim_default_global.png')
153+
# viewLim is set to projection bounds in __clear.
157154
expected = np.array([[-180, -90], [180, 90]])
158155
assert_array_almost_equal(ax.viewLim.frozen().get_points(),
159156
expected)
157+
plt.gcf().draw_without_rendering()
158+
assert_array_almost_equal(ax.viewLim.frozen().get_points(),
159+
expected)

0 commit comments

Comments
 (0)