Histogram with Boxplot above in Python

前端 未结 2 589
臣服心动
臣服心动 2021-01-31 11:38

Hi I wanted to draw a histogram with a boxplot appearing the top of the histogram showing the Q1,Q2 and Q3 as well as the outliers. Example phone is below. (I am using Python an

2条回答
  •  忘掉有多难
    2021-01-31 12:12

    import numpy as np
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    sns.set(style="ticks")
    
    x = np.random.randn(100)
    
    f, (ax_box, ax_hist) = plt.subplots(2, sharex=True, 
                                        gridspec_kw={"height_ratios": (.15, .85)})
    
    sns.boxplot(x, ax=ax_box)
    sns.distplot(x, ax=ax_hist)
    
    ax_box.set(yticks=[])
    sns.despine(ax=ax_hist)
    sns.despine(ax=ax_box, left=True)
    

提交回复
热议问题