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
  • 10,450
  • 29
  • 41
  • 68
miguel
  • 9
  • 2
  • 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
  • FYI: Thoroughly answering questions is time-consuming. If your question is **solved**, say thank you by _**accepting** the solution that is **best for your needs**_. The **✔** is below the **▲** / **▼** arrow, at the top left of the answer. A new solution can be accepted if a better one shows up. You may also vote on the usefulness of an answer with the **▲** / **▼** arrow, if you have a 15+ reputation. **Leave a comment if a solution doesn't answer the question**. [What should I do when someone answers my question?](https://stackoverflow.com/help/someone-answers). Thank you – Zephyr Sep 26 '21 at 11:05

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
  • 195,464
  • 25
  • 298
  • 322
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
  • 10,450
  • 29
  • 41
  • 68