Changing what the ends of whiskers represent in matplotlib's boxplot function

后端 未结 2 1420
抹茶落季
抹茶落季 2021-02-14 02:52

I understand that the ends of whiskers in matplotlib\'s box plot function extend to max value below 75% + 1.5 IQR and minimum value above 25% - 1.5 IQR. I would like to change

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-14 03:47

    Set the boxplot option whisk=0 to hide the inbuilt whiskers. Then create the custom whiskers that show data from 5% to 95%.

    #create markings that represent the ends of whiskers
    low=data.quantile(0.05) 
    high=data.quantile(0.95)
    plt.scatter(range(1,len(low)+1),low,marker='_')
    plt.scatter(range(1,len(low)+1),high,marker='_')
    #connects low and high markers with a line
    plt.vlines(range(1,len(low)+1),low,high)
    

    That should create vertical lines with whisker markings behind the boxes at 5% at 95%.

提交回复
热议问题