色相图

时间:2018-09-25 22:47:20

标签: python python-3.x seaborn

我想绘制一个多列的海洋猫图,并使用色相区分某些观察结果。

让我说

import pandas as pd
import seaborn as sns
import random as r
import numpy as np

name_list=['pepe','Fabrice','jim','Michael']
country_list=['spain','France','uk','Uruguay']
favourite_color=['green','blue','red','white']

df=pd.DataFrame({'name':[r.choice(name_list) for n in range(100)],
         'country':[r.choice(country_list) for n in range(100)],
         'fav_color':[r.choice(favourite_color) for n in range(100)],
         'score':np.random.rand(100),})

如果我跑步

sns.catplot(y='score',hue='fav_color',col='country',data=df)

我收到一个 TypeError:'NoneType'对象不可迭代。如果我指定legend = False,则不会出现任何错误,但是所有点看起来都是相同的颜色。我也尝试指定具有相同结果的调色板。这是错误还是我做错了什么?

1 个答案:

答案 0 :(得分:0)

您可以尝试使用点或条等类型的不同选项将X作为色相值。

    sns.catplot(y='score', x='fav_color',col='country',data=df, kind='point')
    sns.catplot(y='score', x='fav_color',col='country',data=df)

OR

指定kind ='count',不带有这样的X变量

    sns.catplot(y='score',hue='fav_color',col='country',data=df,kind='count')