Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
ncx, ncy = x.shape[1], y.shape[1]
if ncx > 1 and ncy > 1 and ncx != ncy:
raise ValueError(f"x has {ncx} columns but y has {ncy} columns")
if ncx == 0 or ncy == 0:
return []

label = kwargs.get('label')
n_datasets = max(ncx, ncy)
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7153,3 +7153,17 @@ def test_artist_sublists():
# Adding to other lists should produce a regular list.
assert ax.lines + [1, 2, 3] == [*lines, 1, 2, 3]
assert [1, 2, 3] + ax.lines == [1, 2, 3, *lines]


def test_empty_line_plots():
# Incompatible nr columns, plot "nothing"
x = np.ones(10)
y = np.ones((10, 0))
_, ax = plt.subplots()
line = ax.plot(x, y)
assert len(line) == 0

# Ensure plot([],[]) creates line
_, ax = plt.subplots()
line = ax.plot([], [])
assert len(line) == 1