-2

我想使用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?

4

1 回答 1

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])
于 2018-04-03T09:13:57.013 回答