...

/

Visualization with Count Plots

Visualization with Count Plots

Learn how to style and customize count plots according to the needs of the data.

Overview

Count plots are used to count the number of instances each category has. We use it for categorical data to represent the number of instances of each unique category in the form of bars.

Plotting count plots

Let’s start by importing the required libraries and the tips dataset from seaborn library using the sns.load_dataset() function. Next, we can view the first five data records to get an overview of the data using the pandas head() function.

Press + to interact
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_theme()
tips_df = sns.load_dataset('tips')
print(tips_df.head())

Let’s check the ratio of male and female customers in the tips dataset by passing x='sex' to the sns.countplot() function. The sns.countplot() function returns a bar container with all “artists” describing the bars in a count plot. Next, we call the bar_label() function to add labels to the bar. The function takes a ...