perf: defer matplotlib imports and lazy-load plot submodule#330
Merged
perf: defer matplotlib imports and lazy-load plot submodule#330
Conversation
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>
This was referenced Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace module-level
import matplotlib.pyplot as pltwithsubplots()wrappers fromautoarray.plot.utilsacross all plot files. Moveplot_utils.pytoautogalaxy/util/to break a circular import between plot submodules andplot/__init__. Lazy-load the plot submodule via__getattr__inautogalaxy/__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_utilsfunctions are now also available atautogalaxy.util.plot_utils. The original path still works (re-exports unchanged). See full details below.Test Plan
pytest test_autogalaxy/ -x— 811 passed/smoke-testFull API Changes (for automation & release notes)
Added
autogalaxy.util.plot_utils— new module location for plot utility functions (copy ofautogalaxy.plot.plot_utils)Moved (internal imports only)
autogalaxy.util.plot_utilsinstead ofautogalaxy.plot.plot_utilsto avoid circular import withautogalaxy.plot.__init__autogalaxy.plotsubmodule is now lazy-loaded via__getattr__inautogalaxy/__init__Changed
gui/scribbler.py,gui/clicker.py— matplotlib imports moved from module level to inside methodsanalysis/plotter.py—autoarray.plotimport moved to local scope🤖 Generated with Claude Code