I have the following dataframe
it, A B C D
0 10, aa mn cd kk
1 100, ab cd wc ll
2 1000, wc cd mn sf
3 10000, ll ll kk mn
4 100000, wc kk mn cd
5 1000000, aa ll we sf
6 10000000, ss aa ss kk
created as
options = ["ab", "cd", "bb", "aa", "we", "ss", "kk", "mn", "re", "wc", "ll", "sf"]
df = pd.DataFrame(columns=["A", "B", "C", "D"])
for i, it in enumerate([1,2,3,4,5,6,7]):
row = [10**i, random.sample(options, 1)[0], random.sample(options, 1)[0],
random.sample(options, 1)[0], random.sample(options, 1)[0]]
df.loc[i] = row
The goal is to create a scatterplot where y axis are unique values from a dataframe in sorted order e.g options and a-axis corresponds to column it.
Now depending on whether data belongs to column A, B, C, or D I want to color scatter-dots differently and specify a legend. So I know what class a dot comes from.
How do I do it in seaborn or matplotlib?
The way I am doing it in matplotlib is
iters = list(range(df.shape[0]))
x, y = sort(iters, df["A"])
plt.scatter(x, y, color="red")
x, y = sort(iters, df["B"])
plt.scatter(x, y, color="blue")
...
but that does not sort the entire y-axis, only labels that belong to separate columns.
