Seaborn 是一个 Python 的可视化库,基于 Matplotlib 构建,专门用于绘制统计图形。本教程将带您了解 Seaborn 的基本用法和常见图表。
安装 Seaborn
首先,确保您已经安装了 matplotlib
和 pandas
,因为 Seaborn 是在这两个库的基础上构建的。
pip install matplotlib pandas seaborn
基本使用
创建图形
import seaborn as sns
import matplotlib.pyplot as plt
# 创建散点图
sns.scatterplot(x='age', y='score', data=df)
# 显示图形
plt.show()
常见图表
- 散点图
- 条形图
- 折线图
- 箱线图
- 热图
更多图表类型,请访问Seaborn 官方文档。
示例
以下是一个使用 Seaborn 绘制箱线图的示例:
# 创建箱线图
sns.boxplot(x='group', y='value', data=df)
# 显示图形
plt.show()
Boxplot 示例
扩展阅读
想要深入了解 Seaborn,可以阅读以下资源: