Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions autoarray/plot/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def plot_array(
if array is None or array.size == 0:
return

is_rgb = array.ndim == 3 and array.shape[2] in (3, 4)

if colormap is None:
from autoarray.plot.utils import _default_colormap
colormap = _default_colormap()
Expand Down Expand Up @@ -194,21 +196,30 @@ def plot_array(
h, w = array.shape[:2]
_box_aspect = (w / h) if h > 0 else 1.0

im = ax.imshow(
array,
cmap=colormap,
norm=norm,
extent=extent,
aspect="auto", # image fills the axes box; box shape set below
origin=origin_imshow,
)
if is_rgb:
im = ax.imshow(
array,
extent=extent,
aspect="auto",
origin=origin_imshow,
)
else:
im = ax.imshow(
array,
cmap=colormap,
norm=norm,
extent=extent,
aspect="auto", # image fills the axes box; box shape set below
origin=origin_imshow,
)

# Shape the axes box to match the data so there is no surrounding
# whitespace when the panel is embedded in a subplot grid.
ax.set_aspect(_box_aspect, adjustable="box")

from autoarray.plot.utils import _apply_colorbar
_apply_colorbar(im, ax, cb_unit=cb_unit, is_subplot=not owns_figure)
if not is_rgb:
from autoarray.plot.utils import _apply_colorbar
_apply_colorbar(im, ax, cb_unit=cb_unit, is_subplot=not owns_figure)

# --- overlays --------------------------------------------------------------
if array_overlay is not None:
Expand Down
21 changes: 21 additions & 0 deletions test_autoarray/structures/plot/test_structure_plotters.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,24 @@ def test__array_rgb(
)

assert path.join(plot_path, "array_rgb.png") in plot_patch.paths


def test__plot_array_rgb(
array_2d_rgb_7x7,
plot_path,
plot_patch,
):
"""
`plot_array` (the high-level function) must handle `Array2DRGB` inputs without
applying a colormap, norm, or colorbar — all of which would raise errors or
produce nonsense for a 3-channel image.
"""
aplt.plot_array(
array=array_2d_rgb_7x7,
title="RGB Test",
output_path=plot_path,
output_filename="array_rgb_high_level",
output_format="png",
)

assert path.join(plot_path, "array_rgb_high_level.png") in plot_patch.paths
Loading