选择sns swarmplot中的群体位置

时间:2018-04-03 09:02:25

标签: python seaborn

我希望使用sns.swarmplot显示一段时间内的数据变化。我使用以下代码:

import seaborn as sns
import numpy as np

y = np.random.randint(5,size = 40)
time = np.repeat([1,2,3,100],10)
sns.swarmplot(time,y)

然而,这会将时间数据解释为分类,并均匀地传播群体。

有没有办法,群体不均匀分布?那与100相关的所有点都远在右边?

此解决方案是否也适用于sns.violinplot?

1 个答案:

答案 0 :(得分:1)

一个(不是很优雅)解决方案是将所有分类数据提供给sns.swarmplot

import seaborn as sns
import numpy as np

y = np.random.randint(5,size = 40)
time = np.repeat([1,2,3,100],10)

# now add more categorical datas
time_all = np.append(time, np.arange(1,101))
y_all = np.append(y, np.nan*np.arange(100))

sns.swarmplot(time_all,y_all)

# hide all the ticks that are not wanted
plt.x_ticks([1,2,3,100],[1,2,3,100])
相关问题