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

Skip to content

Commit 898888a

Browse files
committed
Don't allow 1D lists as subplot_moasic layout.
1 parent b803891 commit 898888a

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
@@ -1615,6 +1615,8 @@ def _make_array(inp):
16151615
"""
16161616
r0, *rest = inp
16171617
for j, r in enumerate(rest, start=1):
1618+
if isinstance(r, str):
1619+
raise ValueError('List layout specification must be 2D')
16181620
if len(r0) != len(r):
16191621
raise ValueError(
16201622
"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
@@ -725,6 +725,10 @@ def test_empty(self, fig_test, fig_ref, x, empty_sentinel):
725725
axB = fig_ref.add_subplot(gs[1, 1])
726726
axB.set_title(labels[1])
727727

728+
def test_fail_list_of_str(self):
729+
with pytest.raises(ValueError, match='must be 2D'):
730+
plt.subplot_mosaic(['foo', 'bar'])
731+
728732
@check_figures_equal(extensions=["png"])
729733
@pytest.mark.parametrize("subplot_kw", [{}, {"projection": "polar"}, None])
730734
def test_subplot_kw(self, fig_test, fig_ref, subplot_kw):

0 commit comments

Comments
 (0)