V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
如果想在 V2EX 获得更好的推广效果,欢迎了解 PRO 会员机制:
https://www.v2ex.com/pro/about
fanqieipnet
V2EX  ›  推广

如何利用 seaborn 绘制 factorplot 图?

  •  
  •   fanqieipnet · Dec 17, 2020 · 946 views
    This topic created in 1962 days ago, the information mentioned may be changed or developed.
    如何利用 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 图。
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   960 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:36 · PVG 07:36 · LAX 16:36 · JFK 19:36
    ♥ Do have faith in what you're doing.