From 585acb66817f340c0ef651469970bfa52052bec9 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Thu, 26 Mar 2026 09:00:54 +0000 Subject: [PATCH 1/2] Plot improvements: cb_unit for residuals, subplot figsize config, title fontsize config, colorbar labelsize, strip subplot_ from output filenames Co-Authored-By: Claude Sonnet 4.6 --- autogalaxy/analysis/plotter.py | 12 +++---- autogalaxy/config/visualize/general.yaml | 4 +-- autogalaxy/ellipse/plot/fit_ellipse_plots.py | 5 +-- autogalaxy/galaxy/plot/adapt_plots.py | 3 +- autogalaxy/galaxy/plot/galaxies_plots.py | 8 ++--- autogalaxy/galaxy/plot/galaxy_plots.py | 5 +-- autogalaxy/imaging/plot/fit_imaging_plots.py | 32 ++++++++++--------- autogalaxy/interferometer/model/plotter.py | 2 +- .../plot/fit_interferometer_plots.py | 24 +++++++------- autogalaxy/plot/plot_utils.py | 1 - autogalaxy/profiles/plot/basis_plots.py | 3 +- .../quantity/plot/fit_quantity_plots.py | 9 +++--- 12 files changed, 58 insertions(+), 50 deletions(-) diff --git a/autogalaxy/analysis/plotter.py b/autogalaxy/analysis/plotter.py index 0e7fbf49..117fea1e 100644 --- a/autogalaxy/analysis/plotter.py +++ b/autogalaxy/analysis/plotter.py @@ -63,7 +63,7 @@ def __init__(self, image_path: Union[Path, str], title_prefix: str = None): @property def fmt(self) -> List[str]: """The output file format(s) read from ``config/visualize/plots.yaml``.""" - return conf.instance["visualize"]["plots"]["subplot_format"] + return conf.instance["visualize"]["plots"]["format"] def output_from(self) -> aplt.Output: """Return an ``autoarray`` ``Output`` object pointed at ``image_path``.""" @@ -94,7 +94,7 @@ def galaxies( def should_plot(name): return plot_setting(section="galaxies", name=name) - if should_plot("subplot_galaxy_images"): + if should_plot("galaxy_images"): galaxies_plots.subplot_galaxy_images( galaxies=galaxies, grid=grid, @@ -102,7 +102,7 @@ def should_plot(name): output_format=self.fmt, ) - if should_plot("subplot_galaxies"): + if should_plot("galaxies"): galaxies_plots.subplot_galaxies( galaxies=galaxies, grid=grid, @@ -133,7 +133,7 @@ def should_plot(name): output = self.output_from() - if should_plot("subplot_inversion"): + if should_plot("inversion"): from autoarray.inversion.plot.inversion_plots import subplot_of_mapper mapper_list = inversion.cls_list_from(cls=aa.Mapper) @@ -144,7 +144,7 @@ def should_plot(name): inversion=inversion, mapper_index=i, output_path=output.path, - output_filename=f"subplot_inversion_{i}", + output_filename=f"inversion_{i}", output_format=fmt, ) @@ -170,7 +170,7 @@ def should_plot(name): return plot_setting(section="adapt", name=name) if adapt_images.galaxy_name_image_dict is not None: - if should_plot("subplot_adapt_images"): + if should_plot("adapt_images"): adapt_plots.subplot_adapt_images( adapt_galaxy_name_image_dict=adapt_images.galaxy_name_image_dict, output_path=self.image_path, diff --git a/autogalaxy/config/visualize/general.yaml b/autogalaxy/config/visualize/general.yaml index fe424d58..51900f59 100644 --- a/autogalaxy/config/visualize/general.yaml +++ b/autogalaxy/config/visualize/general.yaml @@ -13,10 +13,10 @@ ticks: number_of_ticks_2d: 3 contour: total_contours: 10 - include_values: false + include_values: true colorbar: fraction: 0.047 pad: 0.01 labelrotation: 90 labelsize: 22 - labelsize_subplot: 18 \ No newline at end of file + labelsize_subplot: 22 \ No newline at end of file diff --git a/autogalaxy/ellipse/plot/fit_ellipse_plots.py b/autogalaxy/ellipse/plot/fit_ellipse_plots.py index 071c2097..501c12ae 100644 --- a/autogalaxy/ellipse/plot/fit_ellipse_plots.py +++ b/autogalaxy/ellipse/plot/fit_ellipse_plots.py @@ -5,6 +5,7 @@ import autoarray as aa from autoarray import plot as aplt +from autoarray.plot.utils import conf_subplot_figsize from autogalaxy.ellipse.plot import fit_ellipse_plot_util from autogalaxy.ellipse.fit_ellipse import FitEllipse @@ -147,7 +148,7 @@ def subplot_fit_ellipse( disable_data_contours : bool If ``True``, suppress ellipse contour overlays on the image panel. """ - fig, axes = plt.subplots(1, 2, figsize=(14, 7)) + fig, axes = plt.subplots(1, 2, figsize=conf_subplot_figsize(1, 2)) _plot_data( fit_list=fit_list, @@ -212,7 +213,7 @@ def subplot_ellipse_errors( fit_ellipse_list[i].append(aa.Grid2DIrregular.from_yx_1d(y=y, x=x)) n = len(fit_ellipse_list) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = [axes] if n == 1 else list(axes.flatten()) for i in range(n): diff --git a/autogalaxy/galaxy/plot/adapt_plots.py b/autogalaxy/galaxy/plot/adapt_plots.py index 708c09f5..30f2b3ad 100644 --- a/autogalaxy/galaxy/plot/adapt_plots.py +++ b/autogalaxy/galaxy/plot/adapt_plots.py @@ -3,6 +3,7 @@ from typing import Dict import autoarray as aa +from autoarray.plot.utils import conf_subplot_figsize from autogalaxy.galaxy.galaxy import Galaxy from autogalaxy.plot.plot_utils import plot_array, _save_subplot @@ -45,7 +46,7 @@ def subplot_adapt_images( n = len(adapt_galaxy_name_image_dict) cols = min(n, 3) rows = (n + cols - 1) // cols - fig, axes = plt.subplots(rows, cols, figsize=(7 * cols, 7 * rows)) + fig, axes = plt.subplots(rows, cols, figsize=conf_subplot_figsize(rows, cols)) axes_list = [axes] if n == 1 else list(np.array(axes).flatten()) for i, (_, galaxy_image) in enumerate(adapt_galaxy_name_image_dict.items()): diff --git a/autogalaxy/galaxy/plot/galaxies_plots.py b/autogalaxy/galaxy/plot/galaxies_plots.py index f8f6adb7..227c4767 100644 --- a/autogalaxy/galaxy/plot/galaxies_plots.py +++ b/autogalaxy/galaxy/plot/galaxies_plots.py @@ -5,7 +5,7 @@ from autogalaxy.galaxy.galaxies import Galaxies from autogalaxy.plot.plot_utils import _to_lines, _to_positions, plot_array, plot_grid, _save_subplot, _critical_curves_from -from autoarray.plot.utils import hide_unused_axes +from autoarray.plot.utils import hide_unused_axes, conf_subplot_figsize from autogalaxy import exc @@ -73,7 +73,7 @@ def subplot_galaxies( multiple_images=None, tangential_critical_curves=None, radial_critical_curves=None, - auto_filename="subplot_galaxies", + auto_filename="galaxies", ): """Create a standard five-panel summary subplot for a collection of galaxies. @@ -141,7 +141,7 @@ def _defl_x(): n = len(panels) cols = min(n, 3) rows = (n + cols - 1) // cols - fig, axes = plt.subplots(rows, cols, figsize=(7 * cols, 7 * rows)) + fig, axes = plt.subplots(rows, cols, figsize=conf_subplot_figsize(rows, cols)) axes_flat = [axes] if n == 1 else list(np.array(axes).flatten()) for i, (_, array, title, p, l) in enumerate(panels): @@ -201,7 +201,7 @@ def subplot_galaxy_images( gs = Galaxies(galaxies=galaxies) n = len(gs) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = [axes] if n == 1 else list(axes.flatten()) for i in range(n): diff --git a/autogalaxy/galaxy/plot/galaxy_plots.py b/autogalaxy/galaxy/plot/galaxy_plots.py index d9624896..ffcd72ae 100644 --- a/autogalaxy/galaxy/plot/galaxy_plots.py +++ b/autogalaxy/galaxy/plot/galaxy_plots.py @@ -3,6 +3,7 @@ from typing import TYPE_CHECKING import autoarray as aa +from autoarray.plot.utils import conf_subplot_figsize from autogalaxy.galaxy.galaxy import Galaxy from autogalaxy.profiles.light.abstract import LightProfile @@ -47,7 +48,7 @@ def subplot_of_light_profiles( return n = len(light_profiles) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = [axes] if n == 1 else list(axes.flatten()) for i, lp in enumerate(light_profiles): @@ -129,7 +130,7 @@ def _deflections_x(mp): if not flag: continue - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = [axes] if n == 1 else list(axes.flatten()) for i, mp in enumerate(mass_profiles): diff --git a/autogalaxy/imaging/plot/fit_imaging_plots.py b/autogalaxy/imaging/plot/fit_imaging_plots.py index 8d76e8bd..4268c6b5 100644 --- a/autogalaxy/imaging/plot/fit_imaging_plots.py +++ b/autogalaxy/imaging/plot/fit_imaging_plots.py @@ -1,6 +1,7 @@ import matplotlib.pyplot as plt import autoarray as aa +from autoarray.plot.utils import conf_subplot_figsize from autogalaxy.imaging.fit_imaging import FitImaging from autogalaxy.plot.plot_utils import plot_array, _save_subplot @@ -39,29 +40,30 @@ def subplot_fit( (currently unused). """ panels = [ - (fit.data, "Data"), - (fit.signal_to_noise_map, "Signal-To-Noise Map"), - (fit.model_data, "Model Image"), - (fit.residual_map, "Residual Map"), - (fit.normalized_residual_map, "Normalized Residual Map"), - (fit.chi_squared_map, "Chi-Squared Map"), + (fit.data, "Data", None), + (fit.signal_to_noise_map, "Signal-To-Noise Map", None), + (fit.model_data, "Model Image", None), + (fit.residual_map, "Residual Map", None), + (fit.normalized_residual_map, "Normalized Residual Map", r"$\sigma$"), + (fit.chi_squared_map, "Chi-Squared Map", r"$\chi^2$"), ] n = len(panels) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = list(axes.flatten()) - for i, (array, title) in enumerate(panels): + for i, (array, title, cb_unit) in enumerate(panels): plot_array( array=array, title=title, colormap=colormap, use_log10=use_log10, positions=positions, + cb_unit=cb_unit, ax=axes_flat[i], ) plt.tight_layout() - _save_subplot(fig, output_path, "subplot_fit", output_format) + _save_subplot(fig, output_path, "fit", output_format) def subplot_of_galaxy( @@ -112,7 +114,7 @@ def subplot_of_galaxy( ), ] n = len(panels) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = list(axes.flatten()) for i, (array, title) in enumerate(panels): @@ -125,13 +127,13 @@ def subplot_of_galaxy( ) plt.tight_layout() - _save_subplot(fig, output_path, f"subplot_of_galaxy_{galaxy_index}", output_format) + _save_subplot(fig, output_path, f"of_galaxy_{galaxy_index}", output_format) def subplot_fit_imaging_list( fit_list, output_path=None, - output_filename: str = "subplot_fit_combined", + output_filename: str = "fit_combined", output_format="png", ): """ @@ -152,14 +154,14 @@ def subplot_fit_imaging_list( File format string or list, e.g. ``"png"`` or ``["png"]``. """ n = len(fit_list) - fig, axes = plt.subplots(n, 5, figsize=(35, 7 * n)) + fig, axes = plt.subplots(n, 5, figsize=conf_subplot_figsize(n, 5)) if n == 1: axes = [axes] for i, fit in enumerate(fit_list): plot_array(array=fit.data, title="Data", ax=axes[i][0]) plot_array(array=fit.signal_to_noise_map, title="Signal-To-Noise Map", ax=axes[i][1]) plot_array(array=fit.model_data, title="Model Image", ax=axes[i][2]) - plot_array(array=fit.normalized_residual_map, title="Normalized Residual Map", ax=axes[i][3]) - plot_array(array=fit.chi_squared_map, title="Chi-Squared Map", ax=axes[i][4]) + plot_array(array=fit.normalized_residual_map, title="Normalized Residual Map", cb_unit=r"$\sigma$", ax=axes[i][3]) + plot_array(array=fit.chi_squared_map, title="Chi-Squared Map", cb_unit=r"$\chi^2$", ax=axes[i][4]) plt.tight_layout() _save_subplot(fig, output_path, output_filename, output_format) diff --git a/autogalaxy/interferometer/model/plotter.py b/autogalaxy/interferometer/model/plotter.py index 3a6b3051..8b0a1e51 100644 --- a/autogalaxy/interferometer/model/plotter.py +++ b/autogalaxy/interferometer/model/plotter.py @@ -95,7 +95,7 @@ def should_plot(name): subplot_interferometer_dirty_images( dataset, output_path=self.image_path, - output_filename="subplot_dataset", + output_filename="dataset", output_format=self.fmt[0] if isinstance(self.fmt, (list, tuple)) else self.fmt, ) diff --git a/autogalaxy/interferometer/plot/fit_interferometer_plots.py b/autogalaxy/interferometer/plot/fit_interferometer_plots.py index c85c9e3a..b3faff63 100644 --- a/autogalaxy/interferometer/plot/fit_interferometer_plots.py +++ b/autogalaxy/interferometer/plot/fit_interferometer_plots.py @@ -3,6 +3,7 @@ import autoarray as aa from autoarray.plot import plot_visibilities_1d +from autoarray.plot.utils import conf_subplot_figsize from autogalaxy.interferometer.fit_interferometer import FitInterferometer from autogalaxy.galaxy.plot import galaxies_plots @@ -45,7 +46,7 @@ def subplot_fit( (fit.chi_squared_map, "Chi-Squared Map"), ] n = len(panels) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = list(axes.flatten()) for i, (vis, title) in enumerate(panels): @@ -86,23 +87,24 @@ def subplot_fit_dirty_images( Reserved for future symmetric-colormap support (currently unused). """ panels = [ - (fit.dirty_image, "Dirty Image"), - (fit.dirty_signal_to_noise_map, "Dirty Signal-To-Noise Map"), - (fit.dirty_model_image, "Dirty Model Image"), - (fit.dirty_residual_map, "Dirty Residual Map"), - (fit.dirty_normalized_residual_map, "Dirty Normalized Residual Map"), - (fit.dirty_chi_squared_map, "Dirty Chi-Squared Map"), + (fit.dirty_image, "Dirty Image", None), + (fit.dirty_signal_to_noise_map, "Dirty Signal-To-Noise Map", None), + (fit.dirty_model_image, "Dirty Model Image", None), + (fit.dirty_residual_map, "Dirty Residual Map", None), + (fit.dirty_normalized_residual_map, "Dirty Normalized Residual Map", r"$\sigma$"), + (fit.dirty_chi_squared_map, "Dirty Chi-Squared Map", r"$\chi^2$"), ] n = len(panels) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = list(axes.flatten()) - for i, (array, title) in enumerate(panels): + for i, (array, title, cb_unit) in enumerate(panels): plot_array( array=array, title=title, colormap=colormap, use_log10=use_log10, + cb_unit=cb_unit, ax=axes_flat[i], ) @@ -152,7 +154,7 @@ def subplot_fit_real_space( output_format=output_format, colormap=colormap, use_log10=use_log10, - auto_filename="subplot_fit_real_space", + auto_filename="fit_real_space", ) else: panels = [ @@ -161,7 +163,7 @@ def subplot_fit_real_space( (fit.dirty_residual_map, "Dirty Residual Map"), ] n = len(panels) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = list(axes.flatten()) for i, (array, title) in enumerate(panels): plot_array( diff --git a/autogalaxy/plot/plot_utils.py b/autogalaxy/plot/plot_utils.py index a52384d7..ab684a19 100644 --- a/autogalaxy/plot/plot_utils.py +++ b/autogalaxy/plot/plot_utils.py @@ -218,7 +218,6 @@ def plot_array( output_path=_output_path, output_filename=output_filename, output_format=output_format, - structure=array, ) diff --git a/autogalaxy/profiles/plot/basis_plots.py b/autogalaxy/profiles/plot/basis_plots.py index d8e1b6b6..20d191b7 100644 --- a/autogalaxy/profiles/plot/basis_plots.py +++ b/autogalaxy/profiles/plot/basis_plots.py @@ -2,6 +2,7 @@ import numpy as np import autoarray as aa +from autoarray.plot.utils import conf_subplot_figsize from autogalaxy.profiles.basis import Basis from autogalaxy.plot.plot_utils import _to_positions, plot_array, _save_subplot @@ -59,7 +60,7 @@ def subplot_image( n = len(basis.light_profile_list) cols = min(n, 4) rows = (n + cols - 1) // cols - fig, axes = plt.subplots(rows, cols, figsize=(7 * cols, 7 * rows)) + fig, axes = plt.subplots(rows, cols, figsize=conf_subplot_figsize(rows, cols)) axes_flat = [axes] if n == 1 else list(np.array(axes).flatten()) _positions = _to_positions(positions) diff --git a/autogalaxy/quantity/plot/fit_quantity_plots.py b/autogalaxy/quantity/plot/fit_quantity_plots.py index 5b16dfd5..5f5bf836 100644 --- a/autogalaxy/quantity/plot/fit_quantity_plots.py +++ b/autogalaxy/quantity/plot/fit_quantity_plots.py @@ -1,12 +1,13 @@ import matplotlib.pyplot as plt import autoarray as aa +from autoarray.plot.utils import conf_subplot_figsize from autogalaxy.quantity.fit_quantity import FitQuantity from autogalaxy.plot.plot_utils import plot_array, _save_subplot -def _subplot_fit_array(fit, output_path, output_format, colormap, use_log10, positions, filename="subplot_fit"): +def _subplot_fit_array(fit, output_path, output_format, colormap, use_log10, positions, filename="fit"): """Render a six-panel fit summary subplot for a single array-valued quantity fit. The panels show: data, signal-to-noise map, model image, residual map, @@ -42,7 +43,7 @@ def _subplot_fit_array(fit, output_path, output_format, colormap, use_log10, pos (fit.chi_squared_map, "Chi-Squared Map"), ] n = len(panels) - fig, axes = plt.subplots(1, n, figsize=(7 * n, 7)) + fig, axes = plt.subplots(1, n, figsize=conf_subplot_figsize(1, n)) axes_flat = list(axes.flatten()) for i, (array, title) in enumerate(panels): @@ -96,8 +97,8 @@ def subplot_fit( _subplot_fit_array(fit, output_path, output_format, colormap, use_log10, positions) else: _subplot_fit_array( - fit.y, output_path, output_format, colormap, use_log10, positions, filename="subplot_fit_y" + fit.y, output_path, output_format, colormap, use_log10, positions, filename="fit_y" ) _subplot_fit_array( - fit.x, output_path, output_format, colormap, use_log10, positions, filename="subplot_fit_x" + fit.x, output_path, output_format, colormap, use_log10, positions, filename="fit_x" ) From 43cf586807d9332995a41c835e7d2122162f36be Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Thu, 26 Mar 2026 09:03:41 +0000 Subject: [PATCH 2/2] Hotfix: read subplot_format key from plots.yaml (was incorrectly reading format) Co-Authored-By: Claude Sonnet 4.6 --- autogalaxy/analysis/plotter.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/autogalaxy/analysis/plotter.py b/autogalaxy/analysis/plotter.py index 117fea1e..a196fa96 100644 --- a/autogalaxy/analysis/plotter.py +++ b/autogalaxy/analysis/plotter.py @@ -63,7 +63,10 @@ def __init__(self, image_path: Union[Path, str], title_prefix: str = None): @property def fmt(self) -> List[str]: """The output file format(s) read from ``config/visualize/plots.yaml``.""" - return conf.instance["visualize"]["plots"]["format"] + try: + return conf.instance["visualize"]["plots"]["subplot_format"] + except KeyError: + return conf.instance["visualize"]["plots"]["format"] def output_from(self) -> aplt.Output: """Return an ``autoarray`` ``Output`` object pointed at ``image_path``."""