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

Skip to content

Commit e098780

Browse files
committed
FIX: restore ability of scatter to accept 2-D arrays for x, y, c
1 parent 39f0136 commit e098780

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,12 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
37883788
which case all masks will be combined and only unmasked points
37893789
will be plotted.
37903790
3791+
Fundamentally, scatter works with 1-D arrays; `x`, `y`, `s`,
3792+
and `c` may be input as 2-D arrays, but within scatter
3793+
they will be flattened. The exception is `c`, which
3794+
will be flattened only if its size matches the size of `x`
3795+
and `y`.
3796+
37913797
Examples
37923798
--------
37933799
.. plot:: mpl_examples/shapes_and_collections/scatter_demo.py
@@ -3839,13 +3845,13 @@ def scatter(self, x, y, s=20, c=None, marker='o', cmap=None, norm=None,
38393845
# After this block, c_array will be None unless
38403846
# c is an array for mapping. The potential ambiguity
38413847
# with a sequence of 3 or 4 numbers is resolved in
3842-
# favor mapping, not rgb or rgba.
3848+
# favor of mapping, not rgb or rgba.
38433849
try:
38443850
c_array = np.asanyarray(c, dtype=float)
3845-
if c_array.shape == x.shape:
3851+
if c_array.size == x.size:
38463852
c = np.ma.ravel(c_array)
38473853
else:
3848-
# Wrong shape; it must not be intended for mapping.
3854+
# Wrong size; it must not be intended for mapping.
38493855
c_array = None
38503856
except ValueError:
38513857
# Failed to make a floating-point array; c must be color specs.

0 commit comments

Comments
 (0)