千家信息网

如何进行seaborn的使用

发表于:2025-02-05 作者:千家信息网编辑
千家信息网最后更新 2025年02月05日,今天就跟大家聊聊有关如何进行seaborn的使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。seaborn 是基于matplotlib开发的
千家信息网最后更新 2025年02月05日如何进行seaborn的使用

今天就跟大家聊聊有关如何进行seaborn的使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。


seaborn 是基于matplotlib开发的,提供更高一级的接口,做出的可视化图更加具有表现力。

下面介绍 seaborn 库的入门使用方法,首先导入它和 pyplot 模块:

import matplotlib.pyplot as plt
import seaborn as sns

它里面内置了一些经典数据集,如tips, titanic, iris等,下面依次导入:

tips = sns.load_dataset("tips")
titanic = sns.load_dataset("titanic")
iris = sns.load_dataset("iris")

以titanic 为例,绘制factorplot 图,展示 sex(男、女),不同阶层(1,2,3)的 survived比率:

sns.factorplot(x="pclass", y="survived", hue="sex",data=titanic)

还可以定制 pointplot 图, 调整 markers,linestyles 等参数:

sns.pointplot(x="class", y="survived", hue="sex", data=titanic,
palette={"male":"g","female":"m"},markers=["^","o"],linestyles=["-","--"])

不同阶层下,不同性别的存活比率 barplot 图:

sns.barplot(x="sex",y="survived", hue="class", data=titanic)

统计deck枚举值不同取值的出现频次countplot图:

sns.countplot(x="deck", data=titanic,  palette="Greens_d")

箱形图观察数据分布规律:

sns.boxplot(x="alive", y="age",hue="adult_male",data=titanic)


关于 seaborn 使用,有一张 cheetsheet 图,如下所示:



看完上述内容,你们对如何进行seaborn的使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。

0