自定义散点图

Seaborn 数据可视化入门

Content Team

DataCamp

散点图概览

展示两个定量变量的关系

已学内容:

  • 分面子图(colrow
  • 用颜色区分子组(hue

新增自定义:

  • 用点大小与样式区分子组
  • 调整点透明度

适用于 scatterplot()relplot()

Seaborn 数据可视化入门

用点大小表示子组

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips, 
            kind="scatter", 
            size="size")

plt.show()

点大小变化的散点图

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 数据可视化入门

点大小与色调

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips, 
            kind="scatter", 
            size="size",
            hue="size")

plt.show()

点大小与颜色变化的散点图

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 数据可视化入门

用点样式表示子组

import seaborn as sns
import matplotlib.pyplot as plt

sns.relplot(x="total_bill", 
            y="tip", 
            data=tips, 
            kind="scatter", 
            hue="smoker", 
            style="smoker")

plt.show()

颜色与样式区分的散点图

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 数据可视化入门

调整点透明度

import seaborn as sns
import matplotlib.pyplot as plt

# 将 alpha 设为 0 到 1 之间
sns.relplot(x="total_bill", 
            y="tip", 
            data=tips, 
            kind="scatter", 
            alpha=0.4)

plt.show()

更高透明度的散点图

1 Waskom, M. L. (2021). seaborn: statistical data visualization. https://seaborn.pydata.org/
Seaborn 数据可视化入门

Passons à la pratique !

Seaborn 数据可视化入门

Preparing Video For Download...