Issue
While this question has been answered elsewhere, it doesn't seem to fit what I have tested. I'm very new to this, so please be patient with me. I cannot find any documentation explaining what the c argument does in a way that I understand it.
This is the code I am trying to understand:
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
colors = np.array([0, 10, 20, 30, 40, 45, 50, 55, 60, 70, 80, 90, 100])
plt.scatter(x, y, c=colors)
plt.colorbar()
The answers I have found is that c= is shorthand for color=, but when I replace c= with color=, I get this error:
ValueError: 'color' kwarg must be a color or sequence of color specs. For a sequence of values to be color-mapped, use the 'c' argument instead.
Thank you very much!
Solution
tmdavison kindly pointed out that "c is a shorthand for color for some matplotlib functions, but for scatter, it has a very specific meaning." He then provided the link to the documentation I foolishly did not search under: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html
Answered By - Max
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.