Home > other >  How can I create a colorful scatter plot
How can I create a colorful scatter plot

Time:02-26

I want to create a colorful scatter plot and I have seen a usage of

plt.scatter(x, y, c = 'rby')

But when I use it ,it cant work.

ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not 'rby'

so how can I create a colorful scatter plot by matplotlib

CodePudding user response:

If you want points to be scattered alternatively with red, blue and yellow color, you should provide a list of colors with the same length as your data.

N = len(x)
colors = (list('rby')*(1 N//3))[:N] #messy way of getting ['r', 'b', 'y', 'r',...]
plt.scatter(x, y, c = colors )

result

  • Related