Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a8832f6

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

File tree

Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+2Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+14Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.