When analyzing the distribution of a categorical variable, it is helpful to use a count plot. For example, we were were looking at the sales of ice cream per flavor, we could use a count plot to easily visualize the number of ice cream purchases grouped by the flavor. In this article, we will see how to create a count plot in Seaborn.
To create a count plot in seaborn, we use the countplot
method where we pass a dataframe to the data
named parameter and the a column name to the x
named paramater. Below, we load the titanic data set and count passengers by the ticket class.
import seaborn as sns
titanic = sns.load_dataset("titanic")
sns.countplot(x = "class",
data = titanic)