我正在尝试使用swarmplot
单轴,但数据点的颜色会根据类别而不同。
这是一个例子:
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
data = [
(12, 50, 'Free', 'W'),
(14, 1650, 'Free', 'W'),
(17, 500, 'Free', 'W'),
(17, 200, 'Free', 'W'),
(28, 100, 'Free', 'W'),
(33, 400, 'IM', 'W'),
(36, 200, 'Fly', 'W'),
(48, 100, 'Fly', 'W'),
(52, 200, 'IM', 'W'),
(54, 200, 'Back', 'W'),
(54, 200, 'Breast', 'W'),
(100, 100, 'Breast', 'W'),
(100, 100, 'Back', 'W')
]
rank, dist, stroke, gender = zip(*data)
frame = pd.DataFrame(data={'rank': rank, 'distance': dist,
'stroke': stroke, 'gender': gender})
# this one works, except I don't want to spread the points out
# along the y-axis
# sns.catplot(x='rank', y='distance', hue='stroke', kind='swarm', data=frame)
sns.catplot(x='rank', kind='swarm', data=frame, hue='stroke')
plt.show()
以上失败:
Traceback (most recent call last):
File "test.py", line 31, in <module>
sns.catplot(x='rank', kind='swarm', data=frame, hue='stroke')
File "<...>/python3.6/site-packages/seaborn/categorical.py", line 3765, in catplot
hue_order = list(map(utils.to_utf8, hue_order))
TypeError: 'NoneType' object is not iterable
有没有办法在不提供y
字段的情况下让它工作?