8000 Backport PR #17938: Don't allow 1D lists as subplot_moasic layout. · matplotlib/matplotlib@0c9799e · GitHub
[go: up one dir, main page]

Skip to content

Commit 0c9799e

Browse files
jklymakmeeseeksmachine
authored andcommitted
Backport PR #17938: Don't allow 1D lists as subplot_moasic layout.
1 parent c1c9bc8 commit 0c9799e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,6 +1614,8 @@ def _make_array(inp):
16141614
"""
16151615
r0, *rest = inp
16161616
for j, r in enumerate(rest, start=1):
1617+
if isinstance(r, str):
1618+
raise ValueError('List layout specification must be 2D')
16171619
if len(r0) != len(r):
16181620
raise ValueError(
16191621
"All of the rows must be the same length, however "

lib/matplotlib/tests/test_figure.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@ def test_empty(self, fig_test, fig_ref, x, empty_sentinel):
728728
axB = fig_ref.add_subplot(gs[1, 1])
729729
axB.set_title(labels[1])
730730

731+
def test_fail_list_of_str(self):
732+
with pytest.raises(ValueError, match='must be 2D'):
733+
plt.subplot_mosaic(['foo', 'bar'])
734+
731735
@check_figures_equal(extensions=["png"])
732736
@pytest.mark.parametrize("subplot_kw", [{}, {"projection": "polar"}, None])
733737
def test_subplot_kw(self, fig_test, fig_ref, subplot_kw):

0 commit comments

Comments
 (0)
0