【数据可视化实验-4】数据分布型图表之箱形图

实验内容:
自选数据绘制箱型图描述数据统计分布;
实验目的:
掌握箱型图的绘制方法,能够利用箱型图识别数据中的异常值,判断
数据的偏态和尾重;
实验要求:
选取至少三组不同分布的实际数据集,绘制带误差线的箱形图和箱形
与抖动散点组合图,观察分析数据分布情况。得出观察结果:关键数
值、异常值、数据分布情况、数据分布是否偏斜。
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from plotnine import *
#带误差线的柱形图
Barjitter_plot=(ggplot(df,aes(x='class',y="value",fill="class"))
                +stat_summary(fun_data="mean_sdl",fun_args = {'mult':1},geom="bar", color = "black",size =0.75,width=0.7,show_legend=False)
                +stat_summary(fun_data="mean_sdl", fun_args = {'mult':1},geom="errorbar", color = "black",size =0.75,width=.2,show_legend=False)
                +scale_fill_hue(s = 0.90, l = 0.65, h=0.0417,color_space='husl')
                +ylim(0,7)
                +theme_matplotlib()
                +theme(#legend_position='none',
                    aspect_ratio =1.05,
                    dpi=100,
                    figure_size=(4,4)))
print(Barjitter_plot)

 

#箱形与抖动散点组合图
freq =np.logspace(1,4,num=4-1+1,base=10,dtype='int')
df=pd.DataFrame({'class': np.repeat(['a','b','c','d'], freq),
                 'value':np.random.normal(3, 1, sum(freq))})
box_plot=(ggplot(df,aes(x='class',y="value",fill="class"))
          +geom_boxplot(show_legend=False)
          +scale_fill_hue(s = 0.90, l = 0.65, h=0.0417,color_space='husl')
          +theme_matplotlib()
          +theme(#legend_position='none',
              aspect_ratio =1.1,
              dpi=100,
              figure_size=(4,4)))
print(box_plot)

 

#带误差线柱形与抖动图
Barjitter_plot=(ggplot(df,aes(x='class',y="value",fill="class"))
                +stat_summary(fun_data="mean_sdl", fun_args = {'mult':1},geom="bar", fill="w",color = "black",size=0.75,width=0.7,show_legend=False)
                +stat_summary(fun_data="mean_sdl",fun_args = {'mult':1},geom="errorbar", color = "black",size =0.75,width=.2,show_legend=False)
                +geom_jitter(width=0.3,size=2,stroke=0.1,shape='o',show_legend=False)
                +scale_fill_hue(s = 0.90, l = 0.65, h=0.0417,color_space='husl')
                +ylim(0,7)
                +theme_matplotlib()
                +theme(
                    aspect_ratio =1.05,
                    dpi=100,
                    figure_size=(4,4)))
print(Barjitter_plot)

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值