seaborn入门(2)继续展示seaborn的各种绘图效果

seaborn入门(2)

准备数据集

需要提前下载数据集,详情见[seaborn入门(1)]

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
tips_df = sns.load_dataset(name='tips',cache=True,data_home="./seaborn-data")

设置风格

共有4种风格可以选,分别是"white", “dark”, “whitegrid”, “darkgrid”, “ticks”。

sns.set_style("dark")

简单设置图中元素

  • 设置画布大小
plt.figure(figsize=(8,4))
  • 设置字体
sns.set_context('paper',font_scale=1.4) 

其中’paper’为风格,还有talk,poster等风格

  • 设置坐标轴
    例如下面的代码是删除左边的坐标轴,同理还可以设置bottom = True
sns.despine(left = True)

柱状图

男性女性给的小费差异,默认来看是通过男性给小费的平均值和女性给小费的平均值来进行比较,也可以通过中位数estimator = np.media,标准差np.std,协方差np.cov来估计

sns.barplot(x = 'sex', y = 'total_bill', data = tips_df, estimator=np.mean)

在这里插入图片描述

计数图

与之相比,计数图可以对某个数据集统计数量

sns.countplot(x = 'sex', data = tips_df)

在这里插入图片描述

箱型图

这种图不是很懂啊,希望有大佬来分析以下QwQ

sns.boxplot(x = 'day',y = 'total_bill', data = tips_df, hue = 'sex')

在这里插入图片描述

小提琴图

同上,感觉这图有点骚,大概就是代表数据的分布。

sns.violinplot(x = 'day',y = 'total_bill', data = tips_df, hue = 'sex',split = True)

在这里插入图片描述

剥离图

这是一个代表不同数据点的散点图,其中一个变量是分类变量,代表着数据的平均分布

sns.stripplot(x = 'day',y = 'total_bill', data = tips_df,jitter = True,)

在这里插入图片描述

分簇散点图

sns.swarmplot(x  = 'day',y = 'total_bill', data = tips_df)

算是小提琴图的点状形式吧
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值