You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not sure if this behavior is intentional, but if one makes a scatter plot and provides an array for c which is longer than the number of x, y values, instead of raising an error from the arrays being unevenly shaped, it filled in the colors in incorrectly. Here is an example with the correct colors (because 'colors' is the same length as x and y)
x = np.linspace(0,10)
y = np.sin(x)
colors = x
plt.scatter(x,y, c=colors, cmap=mpl.cm.RdBu, s=100)
Here is one where colors is twice the size of x and y:
x = np.linspace(0,10)
y = np.sin(x)
colors = np.linspace(0,10, 100)
plt.scatter(x,y, c=colors, cmap=mpl.cm.RdBu, s=100)
Seems like the intended behavior would be to have an error thrown, or am I mistaken.
The text was updated successfully, but these errors were encountered:
I believe this behaviour to be unintentional. The c argument can also take a 2-D array of RGB or RGBA values (between 0-1). If matplotlib thinks this is the case it is passed to matplotlib.colors.ColorConverter.to_rgba_array(c. alpha).
The problem is that this function tests if it has been given a single value for the rgba_array in which cases it passes it onto matplotlib.colors.ColorConverter.to_rgba(c. alpha).
Now I have no idea how else this function is used but in this case the error is this. The function only checks that all of entries are bounded between [0, 1] if the length of the array is 4. So in this case length of array is anything then it takes:
r, g, b = arg[:3]
So is the first 3 entries in colors are between [0, 1] then a single RGB color value is chosen defined by these producing the unexpected behaviour.
To check this, in the example given by @hugadams if colors=[1.0, 0.0, 0.0, 10.0, 100.0] it will pass all checks and produce a red coloured plot while colors=[1.1, 0.0, 0.0, 10.0, 100.0] will produce an error as the r value is greater than 1.
As far as I can tell this just needs a small change to check the RGBA single value is of length 4 and this print a suitable error message. As I am new could anyone confirm this and I will be happy to try and implement a PR.
Not sure if this behavior is intentional, but if one makes a scatter plot and provides an array for c which is longer than the number of x, y values, instead of raising an error from the arrays being unevenly shaped, it filled in the colors in incorrectly. Here is an example with the correct colors (because 'colors' is the same length as x and y)
Here is one where colors is twice the size of x and y:
Seems like the intended behavior would be to have an error thrown, or am I mistaken.
The text was updated successfully, but these errors were encountered: