0

I have a similar data to this:

values = (1,1,2,2,3,2,1,3,3,2,1,3,2,1,1)
x = range(len(values))
y = values

values can only contain either 1,2 or 3, and I am struggling to find a way in which I could produce a scatter plot in which 1,2 and 3 values are coloured differently.

Zephyr
  • 11,891
  • 53
  • 45
  • 80
miguel
  • 9
  • 3
  • 1
    `sns.scatterplot(x=x, y=values, hue=values)` works just fine without `hue = list(map(str, y))` and `plt.scatter(x, values, c=values)` works just fine, without using seaborn. – Trenton McKinney Sep 07 '21 at 16:10

2 Answers2

3

Or if using matplotlib, you can just do:

import matplotlib.pyplot as plt
plt.scatter(x, y, c=y)

enter image description here

Psidom
  • 209,562
  • 33
  • 339
  • 356
0

You could use seaborn.scatterplot:

import matplotlib.pyplot as plt
import seaborn as sns

values = (1, 1, 2, 2, 3, 2, 1, 3, 3, 2, 1, 3, 2, 1, 1)
x = range(len(values))
y = values

fig, ax = plt.subplots()

sns.scatterplot(ax = ax, x = x, y = y, hue = list(map(str, y)))

plt.show()

enter image description here

Zephyr
  • 11,891
  • 53
  • 45
  • 80