1

単一の軸で使用しようとして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フィールドを提供せずにこれを機能させる方法はありますか?

4

2 に答える 2