Skip to content

Commit f7cf8b4

Browse files
author
Mike Davidson
committed
Made fb.plot.images more customizable.
1 parent 2343d58 commit f7cf8b4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

foolbox/plot.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ def images(
1313
nrows: Optional[int] = None,
1414
figsize: Optional[Tuple[float, float]] = None,
1515
scale: float = 1,
16+
labels: Any = None,
17+
return_fig: bool = False,
1618
**kwargs: Any,
17-
) -> None:
19+
) -> Optional[Tuple[Any, Any]]:
1820
import matplotlib.pyplot as plt
1921

2022
x: ep.Tensor = ep.astensor(images)
@@ -57,7 +59,7 @@ def images(
5759
nrows=nrows,
5860
figsize=figsize,
5961
squeeze=False,
60-
constrained_layout=True,
62+
constrained_layout=False,
6163
**kwargs,
6264
)
6365

@@ -68,5 +70,11 @@ def images(
6870
ax.set_yticks([])
6971
ax.axis("off")
7072
i = row * ncols + col
73+
if labels is not None:
74+
ax.set_title(labels[i])
7175
if i < len(x):
7276
ax.imshow(x[i])
77+
78+
if return_fig:
79+
return fig, axes
80+
return None

tests/test_plot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def test_plot(dummy: ep.Tensor) -> None:
1313
fbn.plot.images(images, ncols=3)
1414
fbn.plot.images(images, nrows=2, ncols=6)
1515
fbn.plot.images(images, nrows=2, ncols=4)
16+
fbn.plot.images(images, nrows=2, ncols=4, labels=[str(i) for i in range(len(images))])
17+
fbn.plot.images(images, nrows=2, ncols=4, return_fig=True)
1618
with pytest.raises(ValueError):
1719
images = ep.zeros(dummy, (10, 3, 3, 3))
1820
fbn.plot.images(images)

0 commit comments

Comments
 (0)