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

Skip to content

Commit b572eea

Browse files
authored
Merge pull request #16179 from jklymak/auto-backport-of-pr-16175-on-v3.2.x
Backport PR #16175: FIX: ignore axes that aren't visible
2 parents 805f451 + 5375487 commit b572eea

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,7 @@ def _make_ghost_gridspec_slots(fig, gs):
254254
# this gridspec slot doesn't have an axis so we
255255
# make a "ghost".
256256
ax = fig.add_subplot(gs[nn])
257-
ax.set_frame_on(False)
258-
ax.set_xticks([])
259-
ax.set_yticks([])
260-
ax.set_facecolor((1, 0, 0, 0))
257+
ax.set_visible(False)
261258

262259

263260
def _make_layout_margins(ax, renderer, h_pad, w_pad):

lib/matplotlib/backend_bases.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,7 @@ def enter_notify_event(self, guiEvent=None, xy=None):
18531853

18541854
def inaxes(self, xy):
18551855
"""
1856-
Check if a point is in an axes.
1856+
Return the topmost visible `~.axes.Axes` containing the point *xy*.
18571857
18581858
Parameters
18591859
----------
@@ -1864,12 +1864,11 @@ def inaxes(self, xy):
18641864
18651865
Returns
18661866
-------
1867-
axes: topmost axes containing the point, or None if no axes.
1868-
1867+
axes : `~matplotlib.axes.Axes` or None
1868+
The topmost visible axes containing the point, or None if no axes.
18691869
"""
18701870
axes_list = [a for a in self.figure.get_axes()
1871-
if a.patch.contains_point(xy)]
1872-
1871+
if a.patch.contains_point(xy) and a.get_visible()]
18731872
if axes_list:
18741873
axes = cbook._topmost_artist(axes_list)
18751874
else:

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6626,3 +6626,11 @@ def test_aspect_nonlinear_adjustable_datalim():
66266626
ax.apply_aspect()
66276627
assert ax.get_xlim() == pytest.approx([1*10**(1/2), 100/10**(1/2)])
66286628
assert ax.get_ylim() == (1 / 101, 1 / 11)
6629+
6630+
6631+
def test_invisible_axes():
6632+
# invisible axes should not respond to events...
6633+
fig, ax = plt.subplots()
6634+
assert fig.canvas.inaxes((200, 200)) is not None
6635+
ax.set_visible(False)
6636+
assert fig.canvas.inaxes((200, 200)) is None

0 commit comments

Comments
 (0)