countplot() is a special type of bar plot. It shows the frequency of each categorical variable. It is also known as a histogram for categorical variables. It makes operations very simple compared to Matplotlib. In Matplotlib, to create a count plot, first we need to group by the category column and count the frequency of each class. After that, this count is consumed by Matplotlib's bar plot. But the Seaborn count plot offers a single line of code to plot the distribution:
# Create count plot (also known as Histogram)
sns.countplot(x='salary', data=df)
# Show figure
plt.show()
This results in the following output:
In the preceding example, we are counting the salary variable. The count() function takes a single column and DataFrame. So, we can easily conclude from the graph that most of the employees have low and medium salaries. We can also use hue as the second variable. Let's see the following example:
# Create count plot (also known as Histogram...