diff --git a/autolens/__init__.py b/autolens/__init__.py index 995c7cc8f..bb07ae6e0 100644 --- a/autolens/__init__.py +++ b/autolens/__init__.py @@ -85,7 +85,6 @@ from autogalaxy.quantity.dataset_quantity import DatasetQuantity from autogalaxy import convert -from . import plot from . import aggregator as agg from .analysis import model_util from .lens import subhalo @@ -131,3 +130,12 @@ conf.instance.register(__file__) __version__ = "2026.4.5.3" + + +def __getattr__(name): + if name == "plot": + from . import plot + + globals()["plot"] = plot + return plot + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") diff --git a/autolens/analysis/plotter.py b/autolens/analysis/plotter.py index 673a3b2d9..67a07f032 100644 --- a/autolens/analysis/plotter.py +++ b/autolens/analysis/plotter.py @@ -14,7 +14,7 @@ fits_tracer, fits_source_plane_images, ) -from autogalaxy.plot.plot_utils import plot_array +from autogalaxy.util.plot_utils import plot_array class Plotter(AgPlotter): diff --git a/autolens/imaging/model/plotter.py b/autolens/imaging/model/plotter.py index 2f542a448..5fdeb1b92 100644 --- a/autolens/imaging/model/plotter.py +++ b/autolens/imaging/model/plotter.py @@ -1,4 +1,3 @@ -import matplotlib.pyplot as plt import numpy as np from typing import List diff --git a/autolens/imaging/plot/fit_imaging_plots.py b/autolens/imaging/plot/fit_imaging_plots.py index 8bf23565b..d6598964c 100644 --- a/autolens/imaging/plot/fit_imaging_plots.py +++ b/autolens/imaging/plot/fit_imaging_plots.py @@ -1,18 +1,17 @@ import logging -import matplotlib.pyplot as plt import numpy as np from typing import Optional, List import autoarray as aa import autogalaxy as ag -from autogalaxy.plot.plot_utils import plot_array +from autogalaxy.util.plot_utils import plot_array from autoarray.plot.array import _zoom_array_2d -from autoarray.plot.utils import save_figure, hide_unused_axes, conf_subplot_figsize, tight_layout +from autoarray.plot.utils import subplots, save_figure, hide_unused_axes, conf_subplot_figsize, tight_layout from autoarray.plot.utils import numpy_lines as _to_lines from autoarray.inversion.mappers.abstract import Mapper from autoarray.inversion.plot.mapper_plots import plot_mapper -from autogalaxy.plot.plot_utils import _critical_curves_from, _caustics_from +from autogalaxy.util.plot_utils import _critical_curves_from, _caustics_from logger = logging.getLogger(__name__) @@ -243,7 +242,7 @@ def subplot_fit( _compute_critical_curves_from_fit(fit) ) - fig, axes = plt.subplots(3, 4, figsize=conf_subplot_figsize(3, 4)) + fig, axes = subplots(3, 4, figsize=conf_subplot_figsize(3, 4)) axes_flat = list(axes.flatten()) plot_array(array=fit.data, ax=axes_flat[0], title="Data", colormap=colormap) @@ -357,7 +356,7 @@ def subplot_fit_x1_plane( colormap : str, optional Matplotlib colormap name applied to all image panels. """ - fig, axes = plt.subplots(2, 3, figsize=conf_subplot_figsize(2, 3)) + fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3)) axes_flat = list(axes.flatten()) try: @@ -442,7 +441,7 @@ def subplot_fit_log10( _compute_critical_curves_from_fit(fit) ) - fig, axes = plt.subplots(3, 4, figsize=conf_subplot_figsize(3, 4)) + fig, axes = subplots(3, 4, figsize=conf_subplot_figsize(3, 4)) axes_flat = list(axes.flatten()) plot_array(array=fit.data, ax=axes_flat[0], title="Data", colormap=colormap, @@ -540,7 +539,7 @@ def subplot_fit_log10_x1_plane( colormap : str, optional Matplotlib colormap name applied to all image panels. """ - fig, axes = plt.subplots(2, 3, figsize=conf_subplot_figsize(2, 3)) + fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3)) axes_flat = list(axes.flatten()) try: @@ -616,7 +615,7 @@ def subplot_of_planes( plane_indexes = [plane_index] for pidx in plane_indexes: - fig, axes = plt.subplots(1, 4, figsize=conf_subplot_figsize(1, 4)) + fig, axes = subplots(1, 4, figsize=conf_subplot_figsize(1, 4)) axes_flat = list(axes.flatten()) plot_array(array=fit.data, ax=axes_flat[0], title="Data", colormap=colormap) @@ -702,7 +701,7 @@ def subplot_tracer_from_fit( magnification = LensCalc.from_mass_obj(tracer).magnification_2d_from(grid=grid) - fig, axes = plt.subplots(3, 3, figsize=conf_subplot_figsize(3, 3)) + fig, axes = subplots(3, 3, figsize=conf_subplot_figsize(3, 3)) axes_flat = list(axes.flatten()) # Panel 0: Model Image @@ -802,7 +801,7 @@ def subplot_fit_combined( """ n_fits = len(fit_list) n_cols = 6 - fig, axes = plt.subplots(n_fits, n_cols, figsize=conf_subplot_figsize(n_fits, n_cols)) + fig, axes = subplots(n_fits, n_cols, figsize=conf_subplot_figsize(n_fits, n_cols)) if n_fits == 1: all_axes = [list(axes)] else: @@ -876,7 +875,7 @@ def subplot_fit_combined_log10( """ n_fits = len(fit_list) n_cols = 6 - fig, axes = plt.subplots(n_fits, n_cols, figsize=conf_subplot_figsize(n_fits, n_cols)) + fig, axes = subplots(n_fits, n_cols, figsize=conf_subplot_figsize(n_fits, n_cols)) if n_fits == 1: all_axes = [list(axes)] else: diff --git a/autolens/interferometer/plot/fit_interferometer_plots.py b/autolens/interferometer/plot/fit_interferometer_plots.py index c853ce7c1..7a673ba23 100644 --- a/autolens/interferometer/plot/fit_interferometer_plots.py +++ b/autolens/interferometer/plot/fit_interferometer_plots.py @@ -1,18 +1,17 @@ import logging -import matplotlib.pyplot as plt import numpy as np from typing import Optional import autoarray as aa import autogalaxy as ag -from autogalaxy.plot.plot_utils import plot_array +from autogalaxy.util.plot_utils import plot_array from autoarray.plot.yx import plot_yx -from autoarray.plot.utils import save_figure, conf_subplot_figsize, tight_layout +from autoarray.plot.utils import subplots, save_figure, conf_subplot_figsize, tight_layout from autoarray.plot.utils import numpy_lines as _to_lines from autoarray.inversion.mappers.abstract import Mapper from autoarray.inversion.plot.mapper_plots import plot_mapper -from autogalaxy.plot.plot_utils import _critical_curves_from, _caustics_from +from autogalaxy.util.plot_utils import _critical_curves_from, _caustics_from from autolens.lens.plot.tracer_plots import plane_image_from logger = logging.getLogger(__name__) @@ -184,7 +183,7 @@ def subplot_fit( _compute_critical_curve_lines(tracer, _cc_grid) ) - fig, axes = plt.subplots(3, 4, figsize=conf_subplot_figsize(3, 4)) + fig, axes = subplots(3, 4, figsize=conf_subplot_figsize(3, 4)) axes_flat = list(axes.flatten()) # Panel 0: amplitudes vs UV-distances @@ -304,7 +303,7 @@ def subplot_fit_dirty_images( _compute_critical_curve_lines(tracer, _cc_grid) ) - fig, axes = plt.subplots(2, 3, figsize=conf_subplot_figsize(2, 3)) + fig, axes = subplots(2, 3, figsize=conf_subplot_figsize(2, 3)) axes_flat = list(axes.flatten()) plot_array(array=fit.dirty_image, ax=axes_flat[0], title="Dirty Image", @@ -361,7 +360,7 @@ def subplot_fit_real_space( tracer = fit.tracer_linear_light_profiles_to_light_profiles final_plane_index = len(fit.tracer.planes) - 1 - fig, axes = plt.subplots(1, 2, figsize=conf_subplot_figsize(1, 2)) + fig, axes = subplots(1, 2, figsize=conf_subplot_figsize(1, 2)) axes_flat = list(axes.flatten()) if fit.inversion is None: @@ -446,7 +445,7 @@ def subplot_tracer_from_fit( magnification = LensCalc.from_mass_obj(tracer).magnification_2d_from(grid=grid) - fig, axes = plt.subplots(3, 3, figsize=conf_subplot_figsize(3, 3)) + fig, axes = subplots(3, 3, figsize=conf_subplot_figsize(3, 3)) axes_flat = list(axes.flatten()) # Panel 0: Dirty Model Image diff --git a/autolens/lens/plot/sensitivity_plots.py b/autolens/lens/plot/sensitivity_plots.py index 748d7117f..087985b5a 100644 --- a/autolens/lens/plot/sensitivity_plots.py +++ b/autolens/lens/plot/sensitivity_plots.py @@ -1,12 +1,11 @@ """Standalone subplot functions for subhalo sensitivity mapping visualisation.""" -import matplotlib.pyplot as plt import numpy as np from typing import Optional import autoarray as aa -from autogalaxy.plot.plot_utils import plot_array -from autoarray.plot.utils import save_figure, tight_layout +from autogalaxy.util.plot_utils import plot_array +from autoarray.plot.utils import subplots, save_figure, tight_layout def subplot_tracer_images( @@ -59,7 +58,7 @@ def subplot_tracer_images( use_log10 : bool, optional If ``True`` the colour scale is applied on a log10 stretch. """ - from autogalaxy.plot.plot_utils import _critical_curves_from, _caustics_from + from autogalaxy.util.plot_utils import _critical_curves_from, _caustics_from from autoarray.plot.utils import numpy_lines as _to_lines grid = aa.Grid2D.from_mask(mask=mask) @@ -94,7 +93,7 @@ def subplot_tracer_images( residual_map = lensed_source_image - lensed_source_image_no_perturb - fig, axes = plt.subplots(1, 6, figsize=(42, 7)) + fig, axes = subplots(1, 6, figsize=(42, 7)) plot_array(array=image, ax=axes[0], title="Image", colormap=colormap, use_log10=use_log10) @@ -180,7 +179,7 @@ def subplot_sensitivity( above_threshold = np.where(log_likelihoods > 5.0, 1.0, 0.0) above_threshold = aa.Array2D(values=above_threshold, mask=log_likelihoods.mask) - fig, axes = plt.subplots(2, 4, figsize=(28, 14)) + fig, axes = subplots(2, 4, figsize=(28, 14)) axes_flat = list(axes.flatten()) plot_array(array=data_subtracted, ax=axes_flat[0], title="Subtracted Image", @@ -285,7 +284,7 @@ def subplot_figures_of_merit_grid( remove_zeros=remove_zeros, ) - fig, ax = plt.subplots(1, 1, figsize=(7, 7)) + fig, ax = subplots(1, 1, figsize=(7, 7)) plot_array(array=figures_of_merit, ax=ax, title="Increase in Log Evidence", colormap=colormap) tight_layout() diff --git a/autolens/lens/plot/subhalo_plots.py b/autolens/lens/plot/subhalo_plots.py index 91a098ab0..c2f576963 100644 --- a/autolens/lens/plot/subhalo_plots.py +++ b/autolens/lens/plot/subhalo_plots.py @@ -1,9 +1,8 @@ """Standalone subplot functions for subhalo detection visualisation.""" -import matplotlib.pyplot as plt from typing import Optional -from autogalaxy.plot.plot_utils import plot_array -from autoarray.plot.utils import save_figure, tight_layout +from autogalaxy.util.plot_utils import plot_array +from autoarray.plot.utils import subplots, save_figure, tight_layout from autolens.imaging.plot.fit_imaging_plots import _plot_source_plane @@ -57,7 +56,7 @@ def subplot_detection_imaging( If ``True`` grid positions where the figure of merit is exactly zero are masked out before plotting. """ - fig, axes = plt.subplots(1, 4, figsize=(28, 7)) + fig, axes = subplots(1, 4, figsize=(28, 7)) plot_array( array=fit_imaging_with_subhalo.data, @@ -141,7 +140,7 @@ def subplot_detection_fits( colormap : str, optional Matplotlib colormap name. """ - fig, axes = plt.subplots(2, 3, figsize=(21, 14)) + fig, axes = subplots(2, 3, figsize=(21, 14)) plot_array( array=fit_imaging_no_subhalo.normalized_residual_map, diff --git a/autolens/lens/plot/tracer_plots.py b/autolens/lens/plot/tracer_plots.py index e0d6a1c41..2cf6bd78d 100644 --- a/autolens/lens/plot/tracer_plots.py +++ b/autolens/lens/plot/tracer_plots.py @@ -1,12 +1,11 @@ -import matplotlib.pyplot as plt import numpy as np from typing import Optional, List import autoarray as aa import autogalaxy as ag -from autogalaxy.plot.plot_utils import plot_array -from autoarray.plot.utils import save_figure, hide_unused_axes, conf_subplot_figsize, tight_layout +from autogalaxy.util.plot_utils import plot_array +from autoarray.plot.utils import subplots, save_figure, hide_unused_axes, conf_subplot_figsize, tight_layout from autoarray.plot.utils import numpy_positions as _to_positions @@ -161,7 +160,7 @@ def subplot_tracer( magnification = LensCalc.from_mass_obj(tracer).magnification_2d_from(grid=grid) - fig, axes = plt.subplots(3, 3, figsize=conf_subplot_figsize(3, 3)) + fig, axes = subplots(3, 3, figsize=conf_subplot_figsize(3, 3)) axes_flat = list(axes.flatten()) plot_array(array=image, ax=axes_flat[0], title="Model Image", @@ -227,7 +226,7 @@ def subplot_lensed_images( traced_grids = tracer.traced_grid_2d_list_from(grid=grid) n = tracer.total_planes - fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) + fig, axes = subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = [axes] if n == 1 else list(np.array(axes).flatten()) for plane_index in range(n): @@ -287,7 +286,7 @@ def subplot_galaxies_images( traced_grids = tracer.traced_grid_2d_list_from(grid=grid) n = 2 * tracer.total_planes - 1 - fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) + fig, axes = subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = [axes] if n == 1 else list(np.array(axes).flatten()) idx = 0 diff --git a/autolens/plot/__init__.py b/autolens/plot/__init__.py index 7bce7343e..8b0c05c95 100644 --- a/autolens/plot/__init__.py +++ b/autolens/plot/__init__.py @@ -9,7 +9,7 @@ # --------------------------------------------------------------------------- # Standalone plot helpers (autoarray) # --------------------------------------------------------------------------- -from autogalaxy.plot.plot_utils import plot_array, plot_grid, fits_array +from autogalaxy.util.plot_utils import plot_array, plot_grid, fits_array from autoarray.dataset.plot.imaging_plots import ( subplot_imaging_dataset, diff --git a/autolens/plot/plot_utils.py b/autolens/plot/plot_utils.py index 422e0c1fc..c23bb49c5 100644 --- a/autolens/plot/plot_utils.py +++ b/autolens/plot/plot_utils.py @@ -1 +1 @@ -from autogalaxy.plot.plot_utils import _critical_curves_from, _caustics_from +from autogalaxy.util.plot_utils import _critical_curves_from, _caustics_from diff --git a/autolens/point/plot/fit_point_plots.py b/autolens/point/plot/fit_point_plots.py index cb3380aef..4201b8175 100644 --- a/autolens/point/plot/fit_point_plots.py +++ b/autolens/point/plot/fit_point_plots.py @@ -1,8 +1,7 @@ -import matplotlib.pyplot as plt import numpy as np from typing import Optional -from autoarray.plot.utils import save_figure, conf_subplot_figsize, tight_layout +from autoarray.plot.utils import subplots, save_figure, conf_subplot_figsize, tight_layout def subplot_fit( @@ -36,13 +35,13 @@ def subplot_fit( output_format : str, optional Image format passed to :func:`~autoarray.plot.utils.save_figure`. """ - from autogalaxy.plot.plot_utils import plot_grid + from autogalaxy.util.plot_utils import plot_grid from autoarray.plot.yx import plot_yx has_fluxes = fit.dataset.fluxes is not None n = 2 if has_fluxes else 1 - fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) + fig, axes = subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = [axes] if n == 1 else list(np.array(axes).flatten()) # Positions panel diff --git a/autolens/point/plot/point_dataset_plots.py b/autolens/point/plot/point_dataset_plots.py index 6cd60762d..4fe6c1794 100644 --- a/autolens/point/plot/point_dataset_plots.py +++ b/autolens/point/plot/point_dataset_plots.py @@ -1,8 +1,7 @@ -import matplotlib.pyplot as plt import numpy as np from typing import Optional -from autoarray.plot.utils import save_figure, conf_subplot_figsize, tight_layout +from autoarray.plot.utils import subplots, save_figure, conf_subplot_figsize, tight_layout def subplot_dataset( @@ -32,13 +31,13 @@ def subplot_dataset( output_format : str, optional Image format passed to :func:`~autoarray.plot.utils.save_figure`. """ - from autogalaxy.plot.plot_utils import plot_grid + from autogalaxy.util.plot_utils import plot_grid from autoarray.plot.yx import plot_yx has_fluxes = dataset.fluxes is not None n = 2 if has_fluxes else 1 - fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) + fig, axes = subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = [axes] if n == 1 else list(np.array(axes).flatten()) grid = np.array(