Skip to content

Commit a8832f6

Browse files
authored
Merge pull request matplotlib#20530 from dmatos2012/plot0cols
Plot nothing for incompatible 0 shape in x,y data
2 parents 833658b + cf4c2a8 commit a8832f6

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ 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 ncx == 0 or ncy == 0:
518+
return []
517519

518520
label = kwargs.get('label')
519521
n_datasets = max(ncx, ncy)

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)