Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit beec816

Browse files
committed
Fix interaction between sticky_edges and shared axes.
1 parent 53c8d6a commit beec816

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,14 +2436,19 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
24362436
if tight is not None:
24372437
self._tight = bool(tight)
24382438

2439-
if self.use_sticky_edges and (
2440-
(self._xmargin and scalex and self._autoscaleXon) or
2441-
(self._ymargin and scaley and self._autoscaleYon)):
2442-
stickies = [artist.sticky_edges for artist in self.get_children()]
2443-
else: # Small optimization.
2444-
stickies = []
2445-
x_stickies = np.sort([x for sticky in stickies for x in sticky.x])
2446-
y_stickies = np.sort([y for sticky in stickies for y in sticky.y])
2439+
x_stickies = y_stickies = np.array([])
2440+
if self.use_sticky_edges:
2441+
# Only iterate over axes and artists if needed.
2442+
if self._xmargin and scalex and self._autoscaleXon:
2443+
x_stickies = np.sort(np.concatenate([
2444+
artist.sticky_edges.x
2445+
for ax in self._shared_x_axes.get_siblings(self)
2446+
for artist in ax.get_children()]))
2447+
if self._ymargin and scaley and self._autoscaleYon:
2448+
y_stickies = np.sort(np.concatenate([
2449+
artist.sticky_edges.y
2450+
for ax in self._shared_y_axes.get_siblings(self)
2451+
for artist in ax.get_children()]))
24472452
if self.get_xscale().lower() == 'log':
24482453
x_stickies = x_stickies[x_stickies > 0]
24492454
if self.get_yscale().lower() == 'log':

lib/matplotlib/tests/test_axes.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,21 @@ def test_use_sticky_edges():
398398
assert_allclose(ax.get_ylim(), (-0.5, 1.5))
399399

400400

401+
@check_figures_equal(extensions=["png"])
402+
def test_sticky_shared_axes(fig_test, fig_ref):
403+
# Check that sticky edges work whether they are set in an axes that is a
404+
# "master" in a share, or an axes that is a "follower".
405+
Z = np.arange(15).reshape(3, 5)
406+
407+
ax0 = fig_test.add_subplot(211)
408+
ax1 = fig_test.add_subplot(212, sharex=ax0)
409+
ax1.pcolormesh(Z)
410+
411+
ax0 = fig_ref.add_subplot(212)
412+
ax1 = fig_ref.add_subplot(211, sharex=ax0)
413+
ax0.pcolormesh(Z)
414+
415+
401416
@image_comparison(['offset_points'], remove_text=True)
402417
def test_basic_annotate():
403418
# Setup some data

0 commit comments

Comments
 (0)