0

Seaborn is imho a great package and countplot is a great function with visually pleasing results.

There is a question on how to access-to-bin-counts-in-seaborn-distplot. E.g. the current answer uses numpy.histogram.

The question is, after we get the distributions, and process them as needed, how to create a countplot-equivalent plot using the altered distributions, e.g.

tl;dr: Here is my problem (example taken from seaborn.countplot): enter image description here

code for copy pasting:

%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
ntg
  • 12,950
  • 7
  • 74
  • 95

1 Answers1

1

You can use sns.barplot()

sns.barplot(x = titanic["class"].dtype.categories, y = total_counts)
ntg
  • 12,950
  • 7
  • 74
  • 95
Kefeng91
  • 802
  • 6
  • 10
  • Thnx! Actually, `unique` gives the wrong order (orders alphabetically), fixed the answer to use `titanic["class"].dtype.categories` instead. – ntg Jul 12 '18 at 12:38