カテゴリ用パレット

Pythonでデータ可視化を磨く

Nick Strayer

Instructor

カテゴリデータの例(国、都市、鳥の3パネル)

Pythonでデータ可視化を磨く

知覚の限界

  • カテゴリは10以下に抑える
  • 色覚多様性に配慮する
sns.palplot(sns.color_palette('Set2', 11))

数が多すぎて見分けにくい色の例

Pythonでデータ可視化を磨く
# Assign a new column to dataframe the desired combos
pollution['interesting cities'] = [x if x in ['Long Beach', 'Cincinnati'] 
                                   else 'other' for x in pollution['city'] ]

sns.scatterplot(x="NO2", y="SO2", hue = 'interesting cities', palette='Set2',
                data=pollution.query('year == 2014 & month == 12'))

ロングビーチとシンシナティを別色、他は「other」にまとめた散布図

Pythonでデータ可視化を磨く
colorbrewer_palettes = ['Set1',   'Set2',    'Set3',    'Accent', 
                        'Paired', 'Pastel1', 'Pastel2', 'Dark2']

for pal in colorbrewer_palettes: 
    sns.palplot(pal=sns.color_palette(pal))
    plt.title(pal, loc = 'left')

利用可能なカテゴリ用カラーパレットの例

Pythonでデータ可視化を磨く

順序データ (a)

  • クラス間に順序がある

  • 限られた個数の離散クラス

4つの四分位を示す図

Pythonでデータ可視化を磨く

順序データ (b)

  • クラス間に順序がある

  • 限られた個数の離散クラス

曜日(7日)を示す図

Pythonでデータ可視化を磨く

順序データ (c)

  • クラス間に順序がある

  • 限られた個数の離散クラス

絵文字の表情で幸せ〜悲しいの尺度を示す図

Pythonでデータ可視化を磨く
colorbrewer_palettes = ['Reds', 'Blues', 'YlOrBr', 'PuBuGn', 'GnBu', 'Greys']

for i, pal in enumerate(colorbrewer_palettes): 
    sns.palplot(pal=sns.color_palette(pal, n_colors=i+4))

利用可能な順序パレットの例

Pythonでデータ可視化を磨く
# Make a tertials column using qcut()
pollution['NO2 Tertial'] = pd.qcut(pollution['NO2'], 3, labels = False)

# Plot colored by the computer tertials 
sns.scatterplot(x="CO", y="SO2", hue='NO2 Tertial', palette="OrRd",
                data=pollution.query("city == 'Long Beach' & year == 2014"))

NO2の三分位を赤系の順序カラースケールで表現したCOとSO2の散布図

Pythonでデータ可視化を磨く

カテゴリに色を付けよう

Pythonでデータ可視化を磨く

Preparing Video For Download...