代码之家  ›  专栏  ›  技术社区  ›  Lord Zsolt

仅Seaborn distplot整数

  •  1
  • Lord Zsolt  · 技术社区  · 7 年前

    我的数据是一个介于0到18之间的数字数组。我想画出数字的分布图。

    Impressions
    0      210
    1     1084
    2     2559
    3     4378
    4     5500
    5     5436
    6     4525
    7     3329
    8     2078
    9     1166
    10     586
    11     244
    12     105
    13      51
    14      18
    15       5
    16       3
    dtype: int64
    

    我使用的代码:

    sns.distplot(Impressions,
                  # bins=np.arange(Impressions.min(), Impressions.max() + 1),
                  # kde=False,
                 axlabel=False,
                 hist_kws={'edgecolor':'black', 'rwidth': 1})
    plt.xticks = range(current.Impressions.min(), current.Impressions.max() + 1, 1)
    

    情节如下:

    enter image description here

    我期待的是:

    • 横杆应该互相接触
    • kde线应该简单地连接条的顶部。从外观上看,当前的一个假设在0和0之间 (x, x + 1) ,这就是为什么向下尖峰(这不是必需的,我可以关闭kde)

    我使用的是正确的工具还是distplot不应该用于整数?

    0 回复  |  直到 7 年前
        1
  •  1
  •   Rudra Mohan    6 年前

    你的问题可以用下面的代码解决,

    import seaborn as sns # for data visualization
    import numpy as np # for numeric computing
    import matplotlib.pyplot as plt # for data visualization
    
    arr = np.array([1,2,3,4,5,6,7,8,9])
    
    sns.distplot(arr, bins = arr, kde = False)
    plt.xticks(arr)
    plt.show()
    

    enter image description here

    sns.distplot() 功能。

    无论你将传递到垃圾箱和plt.xticks公司(). 应该是升序。