Skip to content

Commit b6d3336

Browse files
authored
Merge pull request #16175 from jklymak/fix-mouse-ignore-non-visible-axes
FIX: ignore axes that aren't visible
2 parents 52485ff + 9f8235e commit b6d3336

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ def enter_notify_event(self, guiEvent=None, xy=None):
18321832

18331833
def inaxes(self, xy):
18341834
"""
1835-
Return the topmost `~.axes.Axes` containing the point *xy*.
1835+
Return the topmost visible `~.axes.Axes` containing the point *xy*.
18361836
18371837
Parameters
18381838
----------
@@ -1842,11 +1842,10 @@ def inaxes(self, xy):
18421842
Returns
18431843
-------
18441844
axes : `~matplotlib.axes.Axes` or None
1845-
The topmost axes containing the point, or None if no axes.
1845+
The topmost visible axes containing the point, or None if no axes.
18461846
"""
18471847
axes_list = [a for a in self.figure.get_axes()
1848-
if a.patch.contains_point(xy)]
1849-
1848+
if a.patch.contains_point(xy) and a.get_visible()]
18501849
if axes_list:
18511850
axes = cbook._topmost_artist(axes_list)
18521851
else:

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6898,3 +6898,11 @@ def test_pi_get_negative_values():
68986898
fig, ax = plt.subplots()
68996899
with pytest.raises(ValueError):
69006900
ax.pie([5, 5, -3], explode=[0, .1, .2])
6901+
6902+
6903+
def test_invisible_axes():
6904+
# invisible axes should not respond to events...
6905+
fig, ax = plt.subplots()
6906+
assert fig.canvas.inaxes((200, 200)) is not None
6907+
ax.set_visible(False)
6908+
assert fig.canvas.inaxes((200, 200)) is None

0 commit comments

Comments
 (0)