The relevant lines are in the definition of scatter:
# After this block, c_array will be None unless
# c is an array for mapping. The potential ambiguity
# with a sequence of 3 or 4 numbers is resolved in
# favor of mapping, not rgb or rgba.
if c_none or co is not None:
c_array = None
else:
try:
c_array = np.asanyarray(c, dtype=float)
if c_array.size == x.size: # <<- here is the interesting line.
c = np.ma.ravel(c_array)
else:
# Wrong size; it must not be intended for mapping.
c_array = None
except ValueError:
# Failed to make a floating-point array; c must be color specs.
c_array = None
if c_array is None:
colors = c # must be acceptable as PathCollection facecolors
else:
colors = None # use cmap, norm after collection is created
In fact the call to ravel leads to some more funny issues, e.g. the following code "works" when it likely shouldn't:
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(4)
y = np.arange(4)
colors = np.random.rand(2, 2)
fig, ax = plt.subplots()
ax.scatter(x, y, c=colors)
plt.show()
Activity
anntzer commented on Oct 21, 2016
The relevant lines are in the definition of scatter:
# After this block, c_array will be None unless # c is an array for mapping. The potential ambiguity # with a sequence of 3 or 4 numbers is resolved in # favor of mapping, not rgb or rgba. if c_none or co is not None: c_array = None else: try: c_array = np.asanyarray(c, dtype=float) if c_array.size == x.size: # <<- here is the interesting line. c = np.ma.ravel(c_array) else: # Wrong size; it must not be intended for mapping. c_array = None except ValueError: # Failed to make a floating-point array; c must be color specs. c_array = None if c_array is None: colors = c # must be acceptable as PathCollection facecolors else: colors = None # use cmap, norm after collection is createdIn fact the call to ravel leads to some more funny issues, e.g. the following code "works" when it likely shouldn't:
QuLogic commented on Nov 16, 2016
Fixed by #7363, I believe.