A count plot shows the counts of observations in each category using bars. In other words, each categorical variable is represented with a bar and the length or height of the bars is proportional to the values they represent.
Let’s look at an example. Let’s say in the titanic dataset, we want to represent the number of passengers from each class using a count plot. We can use the following Python code for that purpose:
import seaborn from matplotlib import pyplot df = seaborn.load_dataset("titanic") seaborn.countplot(data=df, x="class") pyplot.savefig("seaborn-count-plot.png") pyplot.close()
The resulting count plot will show the number of passengers belonging to each class of titanic. The count plot looks like the following:
0 Comments