Skip to content

Commit ad61da4

Browse files
SkafteNickimergify[bot]Borda
authored
Fix logic mistake in plotting of metric collection (#1783)
* fix logic mistake * changelog --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
1 parent 4cef0ae commit ad61da4

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
189189

190190
- Fixed use of `prefix` and `postfix` in nested `MetricCollection` ([#1773](https://github.com/Lightning-AI/torchmetrics/pull/1773))
191191

192+
193+
- Fixed `ax` plotting logging in `MetricCollection ([#1783](https://github.com/Lightning-AI/torchmetrics/pull/1783))
194+
195+
192196
- Fixed lookup for punkt sources being downloaded in `RougeScore` [#1789](https://github.com/Lightning-AI/torchmetrics/pull/1789)
193197

198+
194199
## [0.11.4] - 2023-03-10
195200

196201
### Fixed

src/torchmetrics/collections.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,8 @@ def plot(
593593
raise ValueError(
594594
f"Expected argument `ax` to be a matplotlib axis object, but got {type(ax)} when `together=True`"
595595
)
596-
if (
597-
not together
598-
and not isinstance(ax, Sequence)
599-
and not all(isinstance(a, _AX_TYPE) for a in ax)
600-
and len(ax) != len(self)
596+
if not together and not (
597+
isinstance(ax, Sequence) and all(isinstance(a, _AX_TYPE) for a in ax) and len(ax) == len(self)
601598
):
602599
raise ValueError(
603600
f"Expected argument `ax` to be a sequence of matplotlib axis objects with the same length as the "

tests/unittests/utilities/test_plot.py

+8
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,14 @@ def test_plot_method_collection(together, num_vals):
824824
assert all(isinstance(f[0], plt.Figure) for f in fig_ax)
825825
assert all(isinstance(f[1], matplotlib.axes.Axes) for f in fig_ax)
826826

827+
# test ax arg
828+
fig, ax = plt.subplots(nrows=len(m_collection), ncols=1)
829+
m_collection.plot(ax=ax.tolist())
830+
831+
fig, ax = plt.subplots(nrows=len(m_collection) + 1, ncols=1)
832+
with pytest.raises(ValueError, match="Expected argument `ax` to be a sequence of matplotlib axis objects with.*"):
833+
m_collection.plot(ax=ax.tolist())
834+
827835

828836
@pytest.mark.parametrize(
829837
("metric_class", "preds", "target"),

0 commit comments

Comments
 (0)