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

Skip to content

Fix scatter() with empty data and c argument #12672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4187,7 +4187,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
if (c_none or
co is not None or
isinstance(c, str) or
(isinstance(c, collections.Iterable) and
(isinstance(c, collections.Iterable) and len(c) > 0 and
isinstance(c[0], str))):
c_array = None
else:
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,11 @@ def test_scatter_color(self):
with pytest.raises(ValueError):
plt.scatter([1, 2, 3], [1, 2, 3], color=[1, 2, 3])

def test_scatter_empty(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test for pandas with a non-0 based index?

# just making sure this does not raise an exception
plt.scatter([], [])
plt.scatter([], [], s=[], c=[])

# Parameters for *test_scatter_c*. NB: assuming that the
# scatter plot will have 4 elements. The tuple scheme is:
# (*c* parameter case, exception regexp key or None if no exception)
Expand Down