Limit the number of groups shown on a county schedule?

Is it possible to show only the top / bottom n groups in sns.countplot() ?

Using an example from a marine site,

 sns.countplot(y="deck", hue="class", data=titanic, palette="Greens_d"); 

enter image description here

Is there a simple (or even relatively simple) way to limit this graph to only three decks (groups) instead of displaying all 7 or is it something that would be better done using sns.bargraph or just plain matplotlib?

+5
source share
2 answers
 import seaborn as sns titanic = sns.load_dataset("titanic") sns.countplot(y="deck", hue="class", data=titanic, palette="Greens_d", order=titanic.deck.value_counts().iloc[:3].index) 

enter image description here

+9
source

Just add a real example instead of a toy dataset. Assuming you have Pandas training_var data frame name, and you want to display the 10th column of the β€œGene” column, the β€œorder =” bit should look like this:

 sb.countplot(x='Gene',data=training_var,order=pd.value_counts(training_var['Gene']).iloc[:10].index) 
+2
source

Source: https://habr.com/ru/post/1232733/


All Articles