Skip to content

Commit cf4c2a8

Browse files
committed
Add test for incompatible 0 column in plots
1 parent 8924ab8 commit cf4c2a8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
514514
ncx, ncy = x.shape[1], y.shape[1]
515515
if ncx > 1 and ncy > 1 and ncx != ncy:
516516
raise ValueError(f"x has {ncx} columns but y has {ncy} columns")
517-
if not ncx or not ncy:
517+
if ncx == 0 or ncy == 0:
518518
return []
519519

520520
label = kwargs.get('label')

lib/matplotlib/tests/test_axes.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7153,3 +7153,17 @@ def test_artist_sublists():
71537153
# Adding to other lists should produce a regular list.
71547154
assert ax.lines + [1, 2, 3] == [*lines, 1, 2, 3]
71557155
assert [1, 2, 3] + ax.lines == [1, 2, 3, *lines]
7156+
7157+
7158+
def test_empty_line_plots():
7159+
# Incompatible nr columns, plot "nothing"
7160+
x = np.ones(10)
7161+
y = np.ones((10, 0))
7162+
_, ax = plt.subplots()
7163+
line = ax.plot(x, y)
7164+
assert len(line) == 0
7165+
7166+
# Ensure plot([],[]) creates line
7167+
_, ax = plt.subplots()
7168+
line = ax.plot([], [])
7169+
assert len(line) == 1

0 commit comments

Comments
 (0)