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
5 changes: 3 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4187,8 +4187,9 @@ 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.abc.Iterable) and
isinstance(c[0], str))):
(isinstance(c, collections.Iterable) and
len(c) > 0 and
isinstance(cbook.safe_first_element(c), str))):
c_array = None
else:
try: # First, does 'c' look suitable for value-mapping?
Expand Down
17 changes: 16 additions & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5828,7 +5828,7 @@ def test_spines_properbbox_after_zoom():
bb = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
# this is what zoom calls:
ax._set_view_from_bbox((320, 320, 500, 500), 'in',
None, False, False)
None, False, False)
bb2 = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
np.testing.assert_allclose(bb.get_points(), bb2.get_points(), rtol=1e-6)

Expand Down Expand Up @@ -5856,3 +5856,18 @@ def test_gettightbbox_ignoreNaN():
t = ax.text(np.NaN, 1, 'Boo')
renderer = fig.canvas.get_renderer()
np.testing.assert_allclose(ax.get_tightbbox(renderer).width, 532.444444)


def test_scatter_series_non_zero_index(pd):
# create non-zero index
ids = range(10, 18)
x = pd.Series(np.random.uniform(size=8), index=ids)
y = pd.Series(np.random.uniform(size=8), index=ids)
c = pd.Series([1, 1, 1, 1, 1, 0, 0, 0], index=ids)
plt.scatter(x, y, c)


def test_scatter_empty_data():
# making sure this does not raise an exception
plt.scatter([], [])
plt.scatter([], [], s=[], c=[])
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,10 @@ def test_contiguous_regions():
assert cbook.contiguous_regions([False]*5) == []
# Empty mask
assert cbook.contiguous_regions([]) == []


def test_safe_first_element_pandas_series(pd):
# delibrately create a pandas series with index not starting from 0
s = pd.Series(range(5), index=range(10, 15))
actual = cbook.safe_first_element(s)
assert actual == 0