8000 Merge pull request #12761 from ImportanceOfBeingErnest/auto-backport-… · matplotlib/matplotlib@760cff7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 760cff7

Browse files
authored
Merge pull request #12761 from ImportanceOfBeingErnest/auto-backport-of-pr-12673-on-v3.0.x
Backport PR #12673 to v3.0.x
2 parents 1969c21 + 9129737 commit 760cff7

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4201,8 +4201,9 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
42014201
if (c_none or
42024202
co is not None or
42034203
isinstance(c, str) or
4204-
(isinstance(c, collections.abc.Iterable) and
4205-
isinstance(c[0], str))):
4204+
(isinstance(c, collections.Iterable) and
4205+
len(c) > 0 and
4206+
isinstance(cbook.safe_first_element(c), str))):
42064207
c_array = None
42074208
else:
42084209
try: # First, does 'c' look suitable for value-mapping?

lib/matplotlib/tests/test_axes.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5820,7 +5820,7 @@ def test_spines_properbbox_after_zoom():
58205820
bb = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
58215821
# this is what zoom calls:
58225822
ax._set_view_from_bbox((320, 320, 500, 500), 'in',
5823-
None, False, False)
5823+
None, False, False)
58245824
bb2 = ax.spines['bottom'].get_window_extent(fig.canvas.get_renderer())
58255825
np.testing.assert_allclose(bb.get_points(), bb2.get_points(), rtol=1e-6)
58265826

@@ -5848,3 +5848,18 @@ def test_gettightbbox_ignoreNaN():
58485848
t = ax.text(np.NaN, 1, 'Boo')
58495849
renderer = fig.canvas.get_renderer()
58505850
np.testing.assert_allclose(ax.get_tightbbox(renderer).width, 532.444444)
5851+
5852+
5853+
def test_scatter_series_non_zero_index(pd):
5854+
# create non-zero index
5855+
ids = range(10, 18)
5856+
x = pd.Series(np.random.uniform(size=8), index=ids)
5857+
y = pd.Series(np.random.uniform(size=8), index=ids)
5858+
c = pd.Series([1, 1, 1, 1, 1, 0, 0, 0], index=ids)
5859+
plt.scatter(x, y, c)
5860+
5861+
5862+
def test_scatter_empty_data():
5863+
# making sure this does not raise an exception
5864+
plt.scatter([], [])
5865+
plt.scatter([], [], s=[], c=[])

lib/matplotlib/tests/test_cbook.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,3 +492,10 @@ def test_flatiter():
492492

493493
assert 0 == next(it)
494494
assert 1 == next(it)
495+
496+
497+
def test_safe_first_element_pandas_series(pd):
498+
# delibrately create a pandas series with index not starting from 0
499+
s = pd.Series(range(5), index=range(10, 15))
500+
actual = cbook.safe_first_element(s)
501+
assert actual == 0

0 commit comments

Comments
 (0)
0