以两种方式区分点(多种颜色不起作用)

2024-05-13 19:43:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的PCA结果,其中每一行显示sampletime组合的结果

from StringIO import StringIO
import pandas as pd
import seaborn as sns

df_s = StringIO("""Sample   Time    x   y
0   Exp1    0h  -44.0426910625  -6.66946205687
1   Exp2    0h  -37.3825733333  -5.67989159254
2   Exp1    3h  0.366657266488  17.4176127714
3   Exp2    3h  -12.7853023359  12.0592970699
4   Exp1    6h  -33.1318646276  -7.93387062942
5   Exp2    6h  -35.3215567965  -8.75857368124
6   Exp1    9h  68.586307295    41.9221609766
7   Exp2    9h  91.0399392697   46.5500992221
8   Exp1    12h 62.6313681546   -54.443978581
9   Exp2    12h 95.7127263528   -57.596455895
10  Exp1    15h -12.017067754   -5.21348259525
11  Exp2    15h -16.3767106327  -8.474475343
12  Exp1    18h -26.9938518971  -8.18853613281
13  Exp2    18h -20.4778384753  -8.4655806925
14  Exp1    21h -20.409894666   1.27248772102
15  Exp2    21h -27.5639568079  -0.627967036349
16  Exp1    24h -32.4391357476  4.54513705357
17  Exp2    24h -24.6789563289  5.35313955253
18  Exp1    Un-synchronized 19.2496870466   23.6248292286
19  Exp2    Un-synchronized 6.03471508018   19.3075106404""")

df = pd.read_table(df_s) # sep="\s+")

g = sns.lmplot("x", "y", data=df, hue="Sample", fit_reg=False)
g.savefig("StackOverflow.pdf")

enter image description here

我的问题是,我不能使用多种色调(直接,至少)。将色调更改为["Sample", "Time"]会导致

ValueError: cannot set an array element with a sequence

我如何用两种方式来区分这些点,即同时显示时间和样本


Tags: sampleimportdftimeas色调unpd