Skip to content

perf: defer matplotlib imports and lazy-load plot submodule#330

Merged
Jammy2211 merged 1 commit intomainfrom
feature/lazy-imports
Apr 7, 2026
Merged

perf: defer matplotlib imports and lazy-load plot submodule#330
Jammy2211 merged 1 commit intomainfrom
feature/lazy-imports

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

Replace module-level import matplotlib.pyplot as plt with subplots() wrappers from autoarray.plot.utils across all plot files. Move plot_utils.py to autogalaxy/util/ to break a circular import between plot submodules and plot/__init__. Lazy-load the plot submodule via __getattr__ in autogalaxy/__init__, deferring ~0.3s of matplotlib import cost to first plot access.

Part of PyAutoLabs/PyAutoLens#426. Depends on PyAutoLabs/PyAutoArray#259.

API Changes

autogalaxy.plot.plot_utils functions are now also available at autogalaxy.util.plot_utils. The original path still works (re-exports unchanged). See full details below.

Test Plan

  • pytest test_autogalaxy/ -x — 811 passed
  • Smoke tests via downstream /smoke-test
Full API Changes (for automation & release notes)

Added

  • autogalaxy.util.plot_utils — new module location for plot utility functions (copy of autogalaxy.plot.plot_utils)

Moved (internal imports only)

  • Plot files now import from autogalaxy.util.plot_utils instead of autogalaxy.plot.plot_utils to avoid circular import with autogalaxy.plot.__init__
  • autogalaxy.plot submodule is now lazy-loaded via __getattr__ in autogalaxy/__init__

Changed

  • gui/scribbler.py, gui/clicker.py — matplotlib imports moved from module level to inside methods
  • analysis/plotter.pyautoarray.plot import moved to local scope

🤖 Generated with Claude Code

Replace module-level matplotlib imports with autoarray.plot.utils
wrappers across all plot files. Move plot_utils.py to autogalaxy/util/
to break a circular import between plot submodules and plot/__init__.
Lazy-load the plot submodule via __getattr__ in autogalaxy/__init__,
deferring ~0.3s of matplotlib import cost to first plot access.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit 85077f6 into main Apr 7, 2026
1 of 2 checks passed
@Jammy2211 Jammy2211 deleted the feature/lazy-imports branch April 7, 2026 17:38
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.

1 participant