Python3 - Categorical Plots: barplot(), countplot(), boxplot(), vionlinplot(), stripplot()... 有料

这次的数据可视化的seaborn是在Jupyter Notebooks上练习的:
要想知道如何创建Jupyter Notebooks, 请点击这里

使用的数据:

import seaborn as sns

tips = sns.load_dataset('tips')
print(tips.head())

结果如下:
在这里插入图片描述
使用barplot():

# barplot(): 条形图主要展现的是每个矩型高度的数值变量的中心趋势的估计
print(sns.barplot(x='sex',y='total_bill',data=tips))

结果如下:
在这里插入图片描述

import numpy as np
# estimator: 设置每个分类箱的统计函数
print(sns.barplot(x='sex',y='total_bill',data=tips,estimator=np.std))

结果如下:
在这里插入图片描述
使用countplot():

# Show the counts of observation in each categorical bin using bars.
print(sns.countplot(x='sex',data=tips))

print(sns.countplot(x='sex',data=tips, facecolor=(0,0,0,0), edgecolor=sns.color_palette("dark",3), linewidth=5))

结果如下:
在这里插入图片描述
使用boxplot():

# boxplot 称为箱型图,是一种用作显示一组数据分散情况资料的统计图
# 它能显示出一组数据的最大值,最小值,中位数及上下四分位数。
print(sns.boxplot(x='day',y='total_bill',data=tips))

# hue(str): dataframe的列名,按照列名中的值分类形成分类的条形图
print(sns.boxplot(x='day',y='total_bill',data=tips,hue='smoker'))

结果如下:
在这里插入图片描述
使用violinplot():

# 小提琴图的外围的曲线宽度代表数据点分布的密度,中间的箱线图则和普通箱线图表征的意义是一样的,代表中位数,上下分位数,极差等
print(sns.violinplot(x='day',y='total_bill',data=tips))

# hue(str): dataframe的列名,按照列名中的值分类形成分类的条形图
print(sns.violinplot(x='day',y='total_bill',data=tips,hue='sex'))

结果如下:
在这里插入图片描述

# sqlit: 当使用带有两种颜色的变量时,将split设置为True,则会为每种颜色绘制对应半边小提琴。从而可以更容易直接的比较分布
print(sns.violinplot(x='day',y='total_bill',data=tips,hue='sex',split=True))

结果如下:
在这里插入图片描述
使用stripplot():

# stripplot()的原理是按照x属性所对应的类别分别展示y属性的值,适用于分类数据
print(sns.stripplot(x='day',y='total_bill',data=tips))

# jitter使数据点分散开
print(sns.stripplot(x='day',y='total_bill',data=tips,jitter=True))

在这里插入图片描述

# hue(str): dataframe的列名,按照列名中的值分类形成分类的条形图
print(sns.stripplot(x='day',y='total_bill',data=tips,jitter=True,hue='sex'))

结果如下:
在这里插入图片描述

# dodge: 控制组内分类是否彻底分拆
print(sns.stripplot(x='day',y='total_bill',data=tips,jitter=True,hue='sex',dodge=True))

# split: 控制组内分类是否彻底分拆
print(sns.stripplot(x='day',y='total_bill',data=tips,jitter=True,hue='sex',split=True))

结果如下:
在这里插入图片描述
使用swarmplot():

# swarmplot: 分簇散点图可以理解为数据点不重叠的分类散点图
print(sns.swarmplot(x='day',y='total_bill',data=tips))

print(sns.violinplot(x='day',y='total_bill',data=tips))
print(sns.swarmplot(x='day',y='total_bill',data=tips,color='black'))

结果如下:
在这里插入图片描述

print(sns.violinplot(x='day',y='total_bill',data=tips))
print(sns.swarmplot(x='day',y='total_bill',data=tips,color='#beabb7'))

结果如下:
在这里插入图片描述
使用factorplot():

# factorplot() method is used to draw a categorical plot onto a FacetGrid (绘制一个分类图)
print(sns.factorplot(x='day',y='total_bill',data=tips,kind='bar'))

print(sns.factorplot(x='day',y='total_bill',data=tips,kind='violin'))

结果如下:
在这里插入图片描述
如果觉得不错,就点赞或者关注或者留言~~
谢谢~ ~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值