代码之家  ›  专栏  ›  技术社区  ›  ntg

使用seaborn distplot或类似的seaborn功能绘制分布图(例如来自bin计数)

  •  0
  • ntg  · 技术社区  · 7 年前

    西伯恩是一个很棒的包裹 countplot 是一个很好的功能,具有令人满意的视觉效果。

    关于如何 access-to-bin-counts-in-seaborn-distplot .例如,当前答案使用 numpy.histogram 是的。

    问题是,在我们得到分布并根据需要对其进行处理之后,如何使用修改后的分布创建countplot等价图,例如。

    tl;dr:这是我的问题(示例取自 seaborn.countplot )以下内容: enter image description here

    复印粘贴代码:

    %matplotlib inline
    import seaborn as sns
    sns.set(style="darkgrid")
    titanic = sns.load_dataset("titanic")
    ax = sns.countplot(x="class", data=titanic)
    
    import numpy as np
    titanic_classes = titanic['class'].map({s:i for i,s in enumerate(titanic['class'].dtype.categories)}).values
    titanic_counts = np.bincount(titanic_classes)
    #now add ship2 counts
    ship2_counts = [8, 9, 25]
    total_counts = titanic_counts + ship2_counts
    total_counts
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   ntg    7 年前

    你可以用 sns.barplot()

    sns.barplot(x = titanic["class"].dtype.categories, y = total_counts)