Skip to content

Commit

Permalink
Merge pull request #16179 from jklymak/auto-backport-of-pr-16175-on-v…
Browse files Browse the repository at this point in the history
…3.2.x

Backport PR #16175: FIX: ignore axes that aren't visible
  • Loading branch information
jklymak committed Jan 10, 2020
2 parents 805f451 + 5375487 commit b572eea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
5 changes: 1 addition & 4 deletions lib/matplotlib/_constrained_layout.py
Expand Up @@ -254,10 +254,7 @@ def _make_ghost_gridspec_slots(fig, gs):
# this gridspec slot doesn't have an axis so we
# make a "ghost".
ax = fig.add_subplot(gs[nn])
ax.set_frame_on(False)
ax.set_xticks([])
ax.set_yticks([])
ax.set_facecolor((1, 0, 0, 0))
ax.set_visible(False)


def _make_layout_margins(ax, renderer, h_pad, w_pad):
Expand Down
9 changes: 4 additions & 5 deletions lib/matplotlib/backend_bases.py
Expand Up @@ -1853,7 +1853,7 @@ def enter_notify_event(self, guiEvent=None, xy=None):

def inaxes(self, xy):
"""
Check if a point is in an axes.
Return the topmost visible `~.axes.Axes` containing the point *xy*.
Parameters
----------
Expand All @@ -1864,12 +1864,11 @@ def inaxes(self, xy):
Returns
-------
axes: topmost axes containing the point, or None if no axes.
axes : `~matplotlib.axes.Axes` or None
The topmost visible axes containing the point, or None if no axes.
"""
axes_list = [a for a in self.figure.get_axes()
if a.patch.contains_point(xy)]

if a.patch.contains_point(xy) and a.get_visible()]
if axes_list:
axes = cbook._topmost_artist(axes_list)
else:
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Expand Up @@ -6626,3 +6626,11 @@ def test_aspect_nonlinear_adjustable_datalim():
ax.apply_aspect()
assert ax.get_xlim() == pytest.approx([1*10**(1/2), 100/10**(1/2)])
assert ax.get_ylim() == (1 / 101, 1 / 11)


def test_invisible_axes():
# invisible axes should not respond to events...
fig, ax = plt.subplots()
assert fig.canvas.inaxes((200, 200)) is not None
ax.set_visible(False)
assert fig.canvas.inaxes((200, 200)) is None

0 comments on commit b572eea

Please sign in to comment.