Python Pandas - Draw a set of Horizontal point plots with Seaborn

Horizontal point plots in Seaborn display point estimates and confidence intervals as scatter plot markers. The pointplot() function creates these visualizations by plotting categorical data on one axis and numerical data on the other.

What is a Point Plot?

A point plot shows the relationship between a numerical variable and a categorical variable. It displays the mean value of the numerical variable for each category, along with confidence intervals indicating the uncertainty around the estimate.

Basic Syntax

seaborn.pointplot(x=None, y=None, data=None, orient=None)

Creating Sample Data

Let's create sample cricket data to demonstrate horizontal point plots ?

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

# Create sample cricket data
data = {
    'Academy': ['Mumbai', 'Delhi', 'Chennai', 'Kolkata', 'Mumbai', 'Delhi', 'Chennai', 'Kolkata'] * 3,
    'Age': [22, 25, 23, 24, 21, 26, 22, 25, 23, 24, 22, 26, 24, 23, 21, 25, 22, 24, 23, 25, 26, 22, 24, 23],
    'Score': [85, 92, 78, 88, 90, 87, 82, 91, 86, 89, 84, 93, 88, 85, 87, 90, 83, 92, 86, 89, 91, 85, 88, 84]
}

df = pd.DataFrame(data)
print(df.head())
   Academy  Age  Score
0   Mumbai   22     85
1    Delhi   25     92
2  Chennai   23     78
3  Kolkata   24     88
4   Mumbai   21     90

Creating a Horizontal Point Plot

To create a horizontal point plot, set the categorical variable on the y-axis and numerical variable on the x-axis ?

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

# Create sample data
data = {
    'Academy': ['Mumbai', 'Delhi', 'Chennai', 'Kolkata'] * 6,
    'Age': [22, 25, 23, 24, 21, 26, 22, 25, 23, 24, 22, 26, 24, 23, 21, 25, 22, 24, 23, 25, 26, 22, 24, 23]
}

df = pd.DataFrame(data)

# Set the theme
sns.set_theme(style="whitegrid")

# Create horizontal point plot
plt.figure(figsize=(8, 5))
sns.pointplot(x='Age', y='Academy', data=df)
plt.title('Average Age by Cricket Academy')
plt.show()

Customizing Point Plot Appearance

You can customize colors, markers, and add additional grouping variables ?

import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt

# Create sample data with additional category
data = {
    'Academy': ['Mumbai', 'Delhi', 'Chennai', 'Kolkata'] * 6,
    'Age': [22, 25, 23, 24, 21, 26, 22, 25, 23, 24, 22, 26, 24, 23, 21, 25, 22, 24, 23, 25, 26, 22, 24, 23],
    'Experience': ['Junior', 'Senior', 'Junior', 'Senior'] * 6
}

df = pd.DataFrame(data)

# Create customized horizontal point plot
plt.figure(figsize=(10, 6))
sns.pointplot(
    x='Age', 
    y='Academy', 
    hue='Experience',
    data=df,
    palette='Set2',
    markers=['o', 's'],
    linestyles=['-', '--']
)
plt.title('Average Age by Academy and Experience Level')
plt.legend(title='Experience Level')
plt.show()

Key Parameters

Parameter Description Example
x, y Variables for x and y axes x='Age', y='Academy'
hue Additional grouping variable hue='Experience'
palette Color scheme palette='Set2'
markers Point marker styles markers=['o', 's']

Conclusion

Horizontal point plots effectively display categorical relationships with confidence intervals. Use sns.pointplot() with x as numerical and y as categorical variables for horizontal orientation. Customize with hue, palette, and markers for enhanced visualization.

Updated on: 2026-03-26T13:37:09+05:30

258 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements