如何利用 seaborn 绘制 factorplot 图?

2020-12-17 17:43:34 +08:00
 fanqieipnet
如何利用 seaborn 绘制 factorplot 图?今天番茄加速就来解答一下。

   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 图。
636 次点击
所在节点    推广
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/736475

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX