Limit the range of x in seaborn distplot KDE estimation

后端 未结 2 494
北荒
北荒 2021-02-08 13:01

Suppose we have an array with numbers between 0 and 1:

arr=np.array([ 0.        ,  0.        ,  0.        ,  0.        ,  0.6934264 ,
               0.        ,          


        
相关标签:
2条回答
  • 2021-02-08 13:28

    Settins plt.xlim(0, 1) beforehand should help :

    plt.xlim(0, 1)
    sns.distplot(arr, hist=False)
    
    0 讨论(0)
  • 2021-02-08 13:36

    The correct way of doing this, is by using the clip keyword instead of range:

    sns.distplot(arr, hist=False, kde_kws={'clip': (0.0, 1.0)})
    

    which will produce:

    Indeed, if you only care about the kde and not the histogram, you can use the kdeplot function, which will produce the same result:

    sns.kdeplot(arr, clip=(0.0, 1.0))
    
    0 讨论(0)
提交回复
热议问题