【发布时间】:2018-03-10 15:16:21
【问题描述】:
我有一个数据框(对象类型,出于事先在某些步骤中插入列表的原因),其中三列看起来像这样
data stimulus trial
0 2 -2 1
1 2 -2 2
2 2 -2 3
3 2 -2 4
4 2 -2 5
5 2 -2 6
6 1 -2 7
...
159 1 2.5 16
目前我正在使用 seaborn,但在我的情节中插入适当的图例时遇到了困难。
# spi_num is my dataframe
sns.swarmplot(x="stimulus", y="data", data=spi_num.astype(np.float), edgecolor="black", linewidth=.9)
sns.boxplot(x="stimulus", y="data", data=spi_num.astype(np.float), saturation=1)
所以我有两个问题。如何顺利地将传奇与 seaborn 融合?以及如何使用 pandas plot 命令获得这个情节?我想我需要这样的东西:
spi_num.astype(np.float).groupby('stimulus').plot.box()
然后我得到 10 个数字(每个刺激一个),每个 xlabel 有 3 个箱线图,即“数据”、“刺激”和“试验”。这不应该给我一个如上图所示的情节吗?至少he does it like this。
构建我的数据框
trial_vec = np.tile(np.arange(16)+1, 10)
stimulus_vec = np.repeat([-2., -1.75, -1., -0.75, -0.5, 0.5, 1., 1.25, 1.75, 2.5 ], 16)
data_vec = np.random.randint(0, 16, size=160)
spi_num = pd.DataFrame({'trial': trial_vec, 'stimulus': stimulus_vec, 'data': data_vec}).astype('object')
【问题讨论】:
标签: python pandas seaborn boxplot