首页 文章

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

提问于
浏览
0

Seaborn是一个伟大的包装,countplot是一个伟大的功能,视觉上令人愉快的结果 .

关于如何access-to-bin-counts-in-seaborn-distplot有一个问题 . 例如 . 目前的答案使用numpy.histogram .

问题是,在我们获得分布并根据需要处理它们之后,如何使用改变的分布创建一个计数图等效图,例如,

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 回答

  • 1

    你可以使用 sns.barplot()

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

相关问题