This is a very basic question but there must be something I'm missing. My data looks like this:
x y z
0 2.7 0.3 a
1 3.4 0.4 b
2 15 1.9 b
3 3 0.4 c
4 7.4 0.8 a
Where z
has n
qualitative values. I would like to plot (x,y)
using z
as a label (i.e. n
different colours, etc.). The way I do it now is essentially restricting to the individual values of z
, looping over them and do one scatterplot at a time. Is there a quicker option?
EDIT: this is my current solution
for i, z in zip(range(4), ["a", "b", "c", "d"]):
df.xs(z).plot(kind="scatter", label=z, x="x", y="y", color=colours[i], ax=ax)
where colours
and ax
are defined elsewhere. The reasons why I dislike this solution are
- Why do I have to put colours manually, I already have a palette and normal plots already loop through it.
- Why should I care about
ax
, Pandas should take care of everything. - (most important!) I don't want to loop through either
["a", "b", "c", "d"]
orset(df.z)
.