Is it possible to show only the top/bottom n groups in asns.countplot()
?
Using an example from the seaborn website,
sns.countplot(y="deck", hue="class", data=titanic, palette="Greens_d");
Is there any easy (or even relatively straightforward) way of limiting this plot to just 3 decks (groups) instead of displaying all 7 or is this something that would be better accomplished with an sns.bargraph
or just plain matplotlib?
countplot() method is used to Show the counts of observations in each categorical bin using bars. Parameters : This method is accepting the following parameters that are described below: x, y: This parameter take names of variables in data or vector data, optional, Inputs for plotting long-form data.
When you use sns. countplot , Seaborn literally counts the number of observations per category for a categorical variable, and displays the results as a bar chart.
countplot. Show the counts of observations in each categorical bin using bars. A count plot can be thought of as a histogram across a categorical, instead of quantitative, variable.
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)
Just adding real example instead of toy dataset. Assuming you have Pandas Data Frame name training_var and you want to display top 10 'Gene' column counts 'order=' bit should look as follows:
sb.countplot(x='Gene',data=training_var,order=pd.value_counts(training_var['Gene']).iloc[:10].index)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With