用 Python 提升数据可视化
Nick Strayer
Instructor

sns.palplot(sns.color_palette('Set2', 11))

# 为数据框添加所需组合的新列
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'))

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')

类别间有顺序
固定数量的离散类别

类别间有顺序
固定数量的离散类别

类别间有顺序
固定数量的离散类别

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))

# 使用 qcut() 创建三分位列
pollution['NO2 Tertial'] = pd.qcut(pollution['NO2'], 3, labels = False)
# 按计算的三分位着色绘图
sns.scatterplot(x="CO", y="SO2", hue='NO2 Tertial', palette="OrRd",
data=pollution.query("city == 'Long Beach' & year == 2014"))

用 Python 提升数据可视化