barplot参数 python_Python可视化22|Seaborn.catplot(下)-boxenplot|barplot

15ba54226401fa4e8192081b57ba9753.png
本文介绍Seaborn.catplot中的 boxenplot|barplot|countplot图

本文速览

欢迎随缘关注@pythonic生物人

ee9ce83f30c72e3e6eba756fe173d3fd.png
seaborn分栏条形图

854a0929a050ba78a99e986da5771f2b.png
seaborn增强箱图图

目录

7、seaborn. boxenplot(增强箱图)
不分类增强箱图boxenplot
分类增强箱图
scale参数
k_depth参数
8、 seaborn. barplot(条形图或柱状图)
分类barplot
分类水平barplot
误差棒属性设置
渐变色调色盘
所有柱子一个颜色
更个性化设置
多重分类barplot
catplot()结合 barplot()和FacetGrid 绘制多子图
9、seaborn. countplot
不分类countplot
分类countplot
catplot()结合countplot和FacetGrid绘制多子图

7、seaborn.boxenplot(增强箱图)

该图为boxplot的加强版,提供更多数据的分布信息【箱子更多了
语法:seaborn.boxenplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, width=0.8, dodge=True, k_depth='proportion', linewidth=None, scale='exponential', outlier_prop=None, showfliers=True, ax=None, **kwargs)
介绍一些特异参数

  • 不分类增强箱图boxenplot
#sepal length(cm)不分类增强箱图boxenplot
plt.figure(dpi=70)
sns.set(style="whitegrid")
sns.boxenplot(y='sepal length(cm)',data=pd_iris,#传入数据pd_iris第一列
              palette=["#e74c3c", "#34495e", "#2ecc71"],
             )

e274f59cf65955dacaa4401334103ace.png
  • 分类增强箱图
#按class分类增强箱图
plt.figure(dpi=70)
sns.set(style="whitegrid")
sns.boxenplot(y='sepal length(cm)',x='class',data=pd_iris1,
              palette=["#e74c3c", "#34495e", "#2ecc71"], 
             )

7243b7c27c8c3d83b29ccd2cb6b1e67e.png
  • scale参数
即箱子呈现模式,可选linear( reduces the width by a constant linear factor),
exponential(默认,uses the proportion of data not covered),
area(proportional to the percentage of data covered,和exponential想反)
#scale参数
for i in list('area,linear,exponential'.split(',')):
    plt.figure(dpi=70)
    sns.set(style="whitegrid")
    sns.boxenplot(y='sepal length(cm)',x='class',data=pd_iris1,
                   palette=["#e74c3c", "#34495e", "#2ecc71"],
                   scale='%s'%i
                  )
    plt.title("scale='%s'"%i)

854a0929a050ba78a99e986da5771f2b.png

388a09bed6dc26f16dba476a292d6c1e.png

c60294954292a533be819d314b14aeda.png
  • k_depth参数
#k_depth参数
for i in list('proportion,tukey,trustworthy'.split(',')):
    plt.figure(dpi=70)
    sns.set(style="whitegrid")
    sns.boxenplot(y='sepal length(cm)',x='class',data=pd_iris1,
                   palette=["#e74c3c", "#34495e", "#2ecc71"],
                   k_depth='%s'%i#箱子数量控制,可选proportion(默认),tukey,trustworthy
                  )
    plt.title("k_depth='%s'"%i)

c507577ff77e22208f0470a6cb19d687.png

af69fdf1217ef16db1d5d9b7f8b7ff23.png

46041b7928b0fbd7919a5239b0fdef15.png

8、 seaborn.barplot(条形图或柱状图)

更基础的更个性化的玩法,参考 :Python可视化|matplotlib12-垂直|水平|堆积条形图详解语法:seaborn.barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=<function mean at 0x105c7d9e0>, ci=95, n_boot=1000, units=None, seed=None, orient=None, color=None, palette=None, saturation=0.75, errcolor='.26', errwidth=None, capsize=None, dodge=True, ax=None, **kwargs)

  • 分类barplot
#按class分类barplot
plt.figure(figsize=(8,5))
sns.set(style="whitegrid",font_scale=1.2)
sns.barplot(y='sepal length(cm)',x='class',data=pd_iris1,
              palette=["#01a2d9","#31A354","#c72e29"], 
             )

f49bac25712b1486402a9966369f0b61.png
  • 分类水平barplot
#按class分类水平barplot
plt.figure(dpi=70)
sns.set(style="whitegrid",font_scale=1.2)
sns.barplot(x='sepal length(cm)',y='class',data=pd_iris1,#将x和y变量换下就可以
              palette=["#01a2d9","#31A354","#c72e29"], 
             )

0b87942db7b10c6f962d241d2aa71813.png
  • 误差棒属性设置
#误差棒属性设置
plt.figure(dpi=70)
sns.set(style="whitegrid",font_scale=1.2)
sns.barplot(y='sepal length(cm)',x='class',data=pd_iris1,
              palette=["#01a2d9","#31A354","#c72e29"],
            ci='sd',#设置误差棒的置信区间,可选'sd',float(默认95,即95%置信区间)
            errcolor='#c72e29',#误差棒颜色
            errwidth=6,#误差棒宽度
            capsize=0.05,#误差棒上下横线长度            
            
             )

b3fcb49ad655d4b204d6e484456ccf51.png
  • 渐变色调色盘
#渐变色调色盘
plt.figure(dpi=70)
sns.set(style="whitegrid",font_scale=1.2)
sns.barplot(y='sepal length(cm)',x='class',data=pd_iris1,
              palette='Greens',
             )

fe562743ae37f1e0ae4df995a48c185c.png
  • 所有柱子一个颜色
#所有柱子一个颜色
plt.figure(dpi=70)
sns.set(style="whitegrid",font_scale=1.2)
sns.barplot(y='sepal length(cm)',x='class',data=pd_iris1,
            color='#d5695d',#单独颜色
            saturation=.4,#饱和度
             )

4d4e74c731544ae3c69a379bc5b6069b.png
  • 更个性化设置

参考matplotlib.axes.Axes.bar()中参数

#更多参数设置matplotlib.axes.Axes.bar()中参数
plt.figure(dpi=70)
sns.set(style="whitegrid",font_scale=1.2)
sns.barplot(y='sepal length(cm)',x='class',data=pd_iris1,
            linewidth=2.5,#柱子外框宽 
            facecolor='#31A354',#柱子填充色
            edgecolor='#c72e29'#柱子外框颜色
             )

4099a723cae3aedc0995da6df5627531.png
  • 多重分类barplot
#按class分类后再按flowering分类barplot
plt.figure(dpi=70)
sns.set(style="whitegrid",font_scale=1.2)
sns.barplot(y='sepal length(cm)',x='class',data=pd_iris1,
              palette=["#01a2d9","#31A354","#c72e29"],
            hue='flowering'
             )

fd69916330541a92cb77253c2b5e5418.png
  • catplot()结合 barplot()和FacetGrid绘制多子图
#使用catplot()结合 barplot()和FacetGrid分图显示
plt.figure(dpi=70)
sns.set(style="whitegrid",font_scale=1.2)
sns.catplot(y='sepal length(cm)',x='class',data=pd_iris1,
            palette=["#01a2d9","#31A354","#c72e29"],
            col='flowering',
            kind='bar',#
             )

ee9ce83f30c72e3e6eba756fe173d3fd.png

9、seaborn.countplot

seaborn.countplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, dodge=True, ax=None, **kwargs)
简单理解为将数据去重,展现每个数据重复conuts数,非常类似barplot()

  • 不分类countplot
#不分类countplot
plt.figure(dpi=90)
sns.set(style="whitegrid",font_scale=1.2)
sns.countplot(x='sepal length(cm)',data=pd_iris1,
              palette=["#1B813E","#E83015","#C1328E"], 
             )

b3dff7c8ffd43de573d3c7142fc428f7.png
  • 分类countplot
#分类countplot
plt.figure(dpi=90)
sns.set(style="whitegrid",font_scale=1.2)
sns.countplot(x='sepal length(cm)',data=pd_iris1,
              hue='class',#以上每个柱子在按class分三个柱子
              palette=["#1B813E","#E83015","#C1328E"], 
             )

5103d63a9f52469ed9bf685444eeca00.png
  • catplot()结合countplot和FacetGrid绘制多子图
#catplot()结合countplot和FacetGrid绘制多子图
#plt.figure(dpi=90)
sns.set(style="whitegrid",font_scale=1)
g=sns.catplot(x='sepal length(cm)',data=pd_iris1,
            hue='class',
            col='class',
            kind='count',#切换为countplot
            palette=["#1B813E","#E83015","#C1328E"], 
             )

95593254c8729d69c321dbcf504bc870.png

参考资料

http://seaborn.pydata.org/generated/seaborn.catplot.html#seaborn.catplot

欢迎随缘关注@pythonic生物人

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值