seaborn 使用简单入门

Python与算法社区

已原创 448 篇原创,干货满满

三步加星标

01

02

03

三步加星标

你好,我是zhenguo

今晚学习 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 图,如下所示:

如果想要这张cheetsheet图,可以添加我微信,备注:seaborn

不必打赏

给我点个赞

就心满意足了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值