• Python 画 箱线图


    Python 画 箱线图

    flyfish

    箱线图 其他名字 盒须图 / 箱形图

    在这里插入图片描述

    横向用正态分布看
    在这里插入图片描述
    垂直看
    在这里插入图片描述

    pandas画

    import pandas as pd
    
    import seaborn as sns  
    import matplotlib.pyplot as plt
    import pandas as pd
    
    df = pd.read_csv('sh300.csv')
    print("原始数据")
    print(df.head(3))
    df = df[['high']]
    #plt.boxplot(df,vert=False)#水平
    plt.boxplot(df,vert=True,showbox=True,showcaps=True,showfliers=True,showmeans=True)#垂直
    plt.show()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    在这里插入图片描述
    matplotlib 画好看点

    import matplotlib.pyplot as plt
    import numpy as np
    
    # Random test data
    np.random.seed(1)
    all_data = [np.random.normal(0, std, size=100) for std in range(1, 4)]
    labels = ['x1', 'x2', 'x3']
    
    fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(9, 4))
    
    # rectangular box plot
    bplot1 = ax1.boxplot(all_data,
                         vert=True,  # vertical box alignment
                         patch_artist=True,  # fill with color
                         labels=labels)  # will be used to label x-ticks
    ax1.set_title('Rectangular box plot')
    
    # notch shape box plot
    bplot2 = ax2.boxplot(all_data,
                         notch=True,  # notch shape
                         vert=True,  # vertical box alignment
                         patch_artist=True,  # fill with color
                         labels=labels)  # will be used to label x-ticks
    ax2.set_title('Notched box plot')
    
    # fill with colors
    colors = ['sandybrown', 'olivedrab', 'steelblue']
    for bplot in (bplot1, bplot2):
        for patch, color in zip(bplot['boxes'], colors):
            patch.set_facecolor(color)
    
    # adding horizontal grid lines
    for ax in [ax1, ax2]:
        ax.yaxis.grid(True)
        ax.set_xlabel('Three separate samples')
        ax.set_ylabel('Observed values')
    
    plt.show()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38

    在这里插入图片描述

    box plot
    n. <统计>箱形图
    亦作 box-and-whisker plot)
    box-and-whisker plot
    box-and-whisker diagram
    n. 盒须图 / 箱线图 / 同 box plot
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    whisker
    ['wɪskər] 
    ['wɪskə] 
    n. 须 / 髯 / 晶须 / 胡须
    
    • 1
    • 2
    • 3
    • 4
    plot
    [plɑːt] 
    [plɒt] 
    n. 阴谋 / 情节 / 小块地 / 图表
    v. 密谋 / 计划 / 设计情节 / 标记
    现在分词: plotting
    过去式: plotted
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    notch
    美[nɑːtʃ] 
    英[nɒtʃ] 
    n. 槽口 / 凹痕 / <北美>山路 / 等级
    
    v. 刻凹痕 / 完成 / 获得 / 赢得
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
  • 相关阅读:
    eNSP实验
    STL迭代器
    LeetCode 341. 扁平化嵌套列表迭代器【设计,迭代器,DFS或栈】中等
    Linux Shell脚本
    美容院沙龙活动方案
    工业智能网关BL110应用之二十七:如何设置COM 透传
    LVS负载均衡
    vscode 关闭tab键选中提示建议
    java语言概述
    蓝牙资讯|三星Galaxy Wearable有望在国内发售,智能戒指成为新宠儿
  • 原文地址:https://blog.csdn.net/flyfish1986/article/details/136337619