Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7ab36a

Browse files
committed
FIX: do not allow single element list of str in subplot_mosaic
Also check that the first element of the a list layout is not a string. closes #19631
1 parent 33c3e72 commit a7ab36a

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,6 +1692,8 @@ def _make_array(inp):
16921692
16931693
"""
16941694
r0, *rest = inp
1695+
if isinstance(r0, str):
1696+
raise ValueError('List layout specification must be 2D')
16951697
for j, r in enumerate(rest, start=1):
16961698
if isinstance(r, str):
16971699
raise ValueError('List layout specification must be 2D')

lib/matplotlib/tests/test_figure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,8 @@ def test_empty(self, fig_test, fig_ref, x, empty_sentinel):
760760
def test_fail_list_of_str(self):
761761
with pytest.raises(ValueError, match='must be 2D'):
762762
plt.subplot_mosaic(['foo', 'bar'])
763+
with pytest.raises(ValueError, match='must be 2D'):
764+
plt.subplot_mosaic(['foo'])
763765

764766
@check_figures_equal(extensions=["png"])
765767
@pytest.mark.parametrize("subplot_kw", [{}, {"projection": "polar"}, None])

0 commit comments

Comments
 (0)