Skip to content

swev-id: matplotlib__matplotlib-23314 | mplot3d: Axes3D should honor set_visible(False)#31

Open
rowan-stein wants to merge 1 commit intomatplotlib__matplotlib-23314from
fix/axes3d-set-visible-23314
Open

swev-id: matplotlib__matplotlib-23314 | mplot3d: Axes3D should honor set_visible(False)#31
rowan-stein wants to merge 1 commit intomatplotlib__matplotlib-23314from
fix/axes3d-set-visible-23314

Conversation

@rowan-stein
Copy link
Collaborator

Task 264 — matplotlib__matplotlib-23314

Summary

  • Fixes an mplot3d bug where Axes3D still draws panes/axes even when the Axes is set invisible via ax.set_visible(False).
  • Change: Add an early return at the top of Axes3D.draw() when not self.get_visible(), mirroring 2D Axes behavior.
  • Adds a focused Agg-based test to validate invisibility.

Linked issue

Reproduction (from report)

import matplotlib.pyplot as plt

fig, (ax1, ax2) = plt.subplots(1, 2, subplot_kw={'projection': '3d'})
ax1.scatter(1,1,1)
ax2.scatter(1,1,1, c='r')
ax1.set_visible(False)

plt.show()

Observed failure

  • Left 3D axes remained visible (background pane and axes/ticks drawn) despite ax1.set_visible(False).

Expected

  • Left axes is invisible (no panes/axes/ticks/children drawn), matching 2D Axes semantics.

Root cause (research)

  • Axes3D.draw() (lib/mpl_toolkits/mplot3d/axes3d.py) drew the background patch and axis panes before calling super().draw(renderer) and did not check Axes.visible first. In contrast, 2D Axes.draw() returns early when invisible.

Fix details

  • In Axes3D.draw(self, renderer), add:
    if renderer is None:
        raise RuntimeError("No renderer defined")
    if not self.get_visible():
        return
    before any drawing calls, then proceed as before. This prevents drawing the patch and axes when invisible and aligns 3D with 2D behavior.

Test added

  • lib/mpl_toolkits/tests/test_mplot3d_visibility.py
    • Renders two 3D subplots, hides the left via set_visible(False), draws with Agg, and asserts the left half contains only background pixels.

Notes

  • CI: Not manually triggered per task rules.
  • Stack trace: None (visual rendering bug).
  • Local test approach: Agg-based pixel inspection (no interactive backends).

…ased visibility test\n\nFixes #29.\n\n- Add early return in Axes3D.draw when Axes is not visible, mirroring 2D Axes.\n- Add unit test ensuring left 3D axes renders nothing when set_visible(False).\n\nTask 264 — matplotlib__matplotlib-23314
@rowan-stein rowan-stein requested a review from a team December 24, 2025 19:59
Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants