【问题标题】:How to make boxplot using matplotlib when i already have all the information?当我已经拥有所有信息时,如何使用 matplotlib 制作箱线图?
【发布时间】:2021-03-10 11:21:42
【问题描述】:

你们能帮我解决我的统计问题吗? 我正在尝试使 Box Plot 完全像这样:

我有所有的信息,比如:

# Median  
medianResult = specificData.median()

# Percentile 25
Q1 = specificData.quantile(0.25)

# Percentile 75
Q3 = specificData.quantile(0.75)


# Reasonable Upper Boundary (RUB)
RUB = Q3 + (1.5 * IQRResult)

# Reasonable Lower Boundary (RLB)
RLB = Q1 - (1.5 * IQRResult)

制作 BoxPlot 还需要其他信息吗?以及如何与上图完全一样?对不起,如果我的英语不好..谢谢你们的帮助

【问题讨论】:

    标签: pandas numpy matplotlib anaconda


    【解决方案1】:

    你可以直接调用matplotlib的ax.bxp(...)。它接受一个字典列表作为它的第一个参数。下面是一个帮助您入门的示例:

    
    import matplotlib.pyplot as plt
    
    medianResult = 49
    # Percentile 25
    Q1 = 44
    # Percentile 75
    Q3 = 57
    IQRResult = Q3 - Q1
    # Reasonable Upper Boundary (RUB)
    RUB = Q3 + (1.5 * IQRResult)
    # Reasonable Lower Boundary (RLB)
    RLB = Q1 - (1.5 * IQRResult)
    
    stat_dict1 = {'med': medianResult,
                  'q1': Q1,
                  'q3': Q3,
                  'whislo': RLB,
                  'whishi': RUB,
                  'fliers': [15, 18],
                  'label': 'Example'}
    fig, ax = plt.subplots()
    ax.bxp(bxpstats=[stat_dict1])
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-13
      • 1970-01-01
      相关资源
      最近更新 更多