seaborn 的 barplot 条形图的用法

barplot 可以将一些统计函数的结果显示在图标上。

  • estimator 指定分组汇总的方式,传入一个函数的引用就可以了,默认是取平均值。
%matplotlib inline
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt


sns.set_style("whitegrid")

tips[['total_bill','day']].groupby('day').sum()

import seaborn as sns

sns.set(style="whitegrid")
tips = sns.load_dataset("tips")
ax = sns.barplot(x="day", y="total_bill", data=tips, estimator=sum)
  • 所以,barplot 可以将 groupby 分组的结果按照指定的汇总方式进行可视化展示。
    其它参数:

  • hue(str):dataframe 的列名,按照列名中的值分类形成分类的条形图;

  • order、hue_order (lists of strings):用于控制条形图的顺序;

  • estimator:控制条形图的取整列数据的什么值;

  • ci(float): 允许的误差的范围(控制误差棒的百分比,在 0-100 之间),若填写 “sd”,则误差棒用标准误差(默认为95);

  • capsize(float):设置误差棒帽条(上下两根横线)的宽度;

参考资料

1、seaborn 官网
http://seaborn.pydata.org/generated/seaborn.barplot.html
2、Seaborn入门系列(二)——barplot&countplot&pointplot
https://www.jianshu.com/p/8bb06d3fd21b

猜你喜欢

转载自blog.csdn.net/lw_power/article/details/82984079