需要提前下载数据集,详情见[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)