0% found this document useful (0 votes)
9 views19 pages

Data Visualization With Seaborn - Python

The document provides a comprehensive tutorial on data visualization using the Seaborn library in Python, detailing various types of plots such as line plots, scatter plots, box plots, and more. It includes syntax, parameters, and examples for each plot type, along with customization options to enhance visual appeal. Additionally, it covers advanced visualizations like pair plots, joint plots, and grid plots for exploring relationships and trends in datasets.

Uploaded by

Gayatri Varanasi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views19 pages

Data Visualization With Seaborn - Python

The document provides a comprehensive tutorial on data visualization using the Seaborn library in Python, detailing various types of plots such as line plots, scatter plots, box plots, and more. It includes syntax, parameters, and examples for each plot type, along with customization options to enhance visual appeal. Additionally, it covers advanced visualizations like pair plots, joint plots, and grid plots for exploring relationships and trends in datasets.

Uploaded by

Gayatri Varanasi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Tutorials

Search... Practice
Sign In
Jobs
a Visualization Tutorial With Python Types Matplotlib Altair Plotly Computer Vision OpenCV Computer Graphics Tutorial Deep Learn

Data Visualization with Seaborn - Python


Last Updated : 10 Dec, 2025

Seaborn is a popular Python library for creating attractive statistical visualizations. Built on Matplotlib and
integrated with Pandas, it simplifies complex plots like line charts, heatmaps and violin plots with minimal
code.

2/4

Creating Plots with Seaborn


Seaborn makes it easy to create clear and informative statistical plots with just a few lines of code. It offers
built-in themes, color palettes, and functions tailored for different types of data.

Let’s see various types of plots with simple code to understand how to use it effectively.

1. Line plot

A line plot shows the relationship between two numeric variables, often over time. It can also compare
multiple groups using different lines.
Syntax:

[Link](x=None, y=None, data=None)

Parameters:
x, y: Numeric input variables. These can be arrays, lists or column names from a DataFrame.
data: DataFrame containing the data.

Example:

import pandas as pd
import [Link] as plt

data = {'Name': ['ANSH', 'SAHIL', 'JAYAN', 'ANURAG'], 'Age': [21, 23, 20, 24]}
df = [Link](data)

[Link]([Link], df['Age'])
[Link]('Index')
[Link]('Age')
[Link]('Age Line Plot')
[Link]()

Output

Line plot

2. Scatter Plot

Scatter plots are used to visualize the relationship between two numerical variables. They help identify
correlations or patterns. It can draw a two-dimensional graph.
Syntax:

[Link](x=None, y=None, data=None)

Parameters:
x, y: Input data variables that should be numeric.
data (optional): Dataset containing the variables.

Returns: An Axes object with the scatter plot.


Example:

import pandas as pd
import seaborn as sns
import [Link] as plt

data = {'Name': ['ANSH', 'SAHIL', 'JAYAN', 'ANURAG'], 'Age': [21, 23, 20, 24]}
df = [Link](data)

[Link](x=[Link], y='Age', data=df)


[Link]()

Output
Scatter plot

3. Box plot

A box plot is the visual representation of the depicting groups of numerical data with their quartiles against
continuous/categorical data.

It consists of 5 key statistics: Minimum ,First Quartile or 25% , Median (Second Quartile) or 50%, Third
Quartile or 75% and Maximum

Syntax:

[Link](x=None, y=None, hue=None, data=None)

Parameters:

x, y, hue: Variables for plotting long-form data.


data: Dataset to plot. If x and y are absent data is treated as wide-form.

Returns: An Axes object with the box plot.


Example:

import pandas as pd
import [Link] as plt
import seaborn as sns

data = {'Name': ['ANSH', 'SAHIL', 'JAYAN', 'ANURAG'], 'Age': [21, 23, 20, 45]}
df = [Link](data)

[Link](y='Age', data=df)
[Link]()

Output
Box plot

4. Violin Plot

A violin plot is similar to a boxplot. It shows several quantitative data across one or more categorical
variables such that those distributions can be compared.
Syntax:

[Link](x=None, y=None, hue=None, data=None)

Parameters:
x, y, hue: Inputs for plotting long-form data.
data: Dataset for plotting.

Example:

import pandas as pd
import seaborn as sns
import [Link] as plt

data = {'Name': ['ANSH', 'SAHIL', 'JAYAN', 'ANURAG'], 'Age': [21, 23, 20, 24]}
df = [Link](data)

[Link](y='Age', data=df)
[Link]()

Output
Violin plot

5. Swarm plot

A swarm plot displays individual data points without overlap along a categorical axis which provides a clear
view of distribution density.
Syntax:

[Link](x=None, y=None, hue=None, data=None)

Parameters:
x, y, hue: Inputs for plotting long-form data.
data: Dataset for plotting.

Example:

import pandas as pd
import seaborn as sns
import [Link] as plt

data = {'Name': ['ANSH', 'SAHIL', 'JAYAN', 'ANURAG'], 'Age': [21, 23, 20, 24]}
df = [Link](data)

[Link](x=[Link], y='Age', data=df)


[Link]()

Output
Swarmplot

6. Bar plot

Barplot represents an estimate of central tendency for a numeric variable with the height of each rectangle
and provides some indication of the uncertainty around that estimate using error bars.
Syntax:

[Link](x=None, y=None, hue=None, data=None)

Parameters :
x, y : Variables or column names for long-form data.
hue : (optional) Column for color encoding.
data : (optional) Dataset to plot.

Returns: Axes object with the bar plot.


Example:

import pandas as pd
import seaborn as sns
import [Link] as plt

data = {'Name': ['ANSH', 'SAHIL', 'JAYAN', 'ANURAG'], 'Age': [21, 23, 20, 24]}
df = [Link](data)

[Link](x='Name', y='Age', data=df)


[Link]()

Output
Bar plot

7. Point plot

Point plot show point estimates and confidence intervals using scatter glyphs which represents the central
tendency of a numeric variable.
Syntax:

[Link](x=None, y=None, hue=None, data=None)

Parameters:
x, y: Inputs for plotting long-form data.
hue: (optional) column name for color encoding.
data: Dataframe as a Dataset for plotting.

Return: Axes object with the point plot.


Example:

import pandas as pd
import seaborn as sns
import [Link] as plt

data = {'Name': ['ANSH', 'SAHIL', 'JAYAN', 'ANURAG'],'Age': [21, 23, 20, 24]}
df = [Link](data)

[Link](x='Name', y='Age', data=df)


[Link]()

Output
Point Plot

8. Count plot

A Count plot displays the number of occurrences of each category using bars to visualize the distribution of
categorical variables.
Syntax :

[Link](x=None, y=None, hue=None, data=None)

Parameters :
x, y: Inputs for plotting long-form data.
hue: (optional) column name for color encoding.
data: Dataframe as a Dataset for plotting.

Returns: Axes object with the count plot.


Example:

import pandas as pd
import seaborn as sns
import [Link] as plt

data = {'Name': ['ANSH', 'SAHIL', 'ANSH', 'JAYAN', 'ANURAG', 'ANURAG', 'ANURAG', 'SAHIL']}
df = [Link](data)

[Link](x='Name', data=df)
[Link]("Frequency of Names")
[Link]()

Output
Countplot

9. KDE Plot

KDE Plot (Kernel Density Estimate) is used for visualizing the Probability Density of a continuous variable
at different values in a continuous variable. We can also plot a single graph for multiple samples which
helps in more efficient data visualization.
Syntax:

[Link](x=None, *, y=None, vertical=False, palette=None, data=None, **kwargs)

Parameters:
x, y: Vectors or data keys.
vertical: Boolean to plot vertically.
palette: Color palette.
data: Dataframe

Example:

from [Link] import load_iris


import pandas as pd
import seaborn as sns
import [Link] as plt

iris = load_iris()
df = [Link]([Link], columns=iris.feature_names)
df['Species'] = [Link]
df['Species'] = df['Species'].map({ 0: 'Setosa', 1: 'Versicolor', 2: 'Virginica'})

[Link](data=df[df['Species'] == 'Virginica'], x='sepal length (cm)', fill=True, label='Virginica')


[Link]()
[Link]()

Output
KDE plot

How to Customize Seaborn Plots with Python?


Customizing Seaborn plots increases their readability and visual appeal which makes the data insights
clearer and more informative. Here are several ways we can customize our plots in Seaborn:

1. Adding Titles and Axis Labels

Adding descriptive titles and axis labels makes our plots more understandable and informative. Using
Matplotlib's [Link](), [Link]() and [Link]() to set titles and axis labels.

import seaborn as sns


import [Link] as plt

iris = sns.load_dataset('iris')
[Link](x='sepal_length', y='sepal_width', data=iris)

# Add plot title and axis labels


[Link]('Sepal Length vs Sepal Width')
[Link]('Sepal Length (cm)')
[Link]('Sepal Width (cm)')
[Link]()

Output
Adding Titles and Labels

2. Built-in Styles and Grids in Seaborn

Seaborn provides built-in styles that control the background and grid of your plots. These styles improve
readability and can be chosen based on your presentation needs.
Available Styles:
darkgrid – Dark background with light gridlines. Great for clear contrast.
whitegrid – White background with light gridlines. Ideal for statistical plots.
dark – Dark background without gridlines. Clean and modern look.
white – Plain white background without gridlines. Good for simple visuals.
ticks – White background with axis ticks styled sharply. Suitable for publications.

import seaborn as sns


import [Link] as plt

sns.set_style("whitegrid")

[Link](x='species', y='petal_length', data=sns.load_dataset('iris'))


[Link]('Petal Length Distribution by Species')
[Link]()

Output
Representation of Whitegrid in Boxplot

3. Customizing Color Palettes

Seaborn makes it easy to enhance the appearance of plots using color palettes. You can choose from built-in
palettes like "deep", "muted", or "bright" or define your own using sns.color_palette(). Customizing colors
improves clarity and helps match your data’s theme or purpose.
a) Using a Built-in Palette:

sns.set_palette("pastel")

[Link](x='species', y='petal_length', data=sns.load_dataset('iris'))


[Link]('Petal Length Distribution by Species')
[Link]()

Output

Using Built in palette

b) Using a Custom Palette:

custom_colors = ['#FF5733', '#33FFBD', '#335BFF']


t l tt ( t l )
sns.set_palette(custom_colors)

[Link](x='species', y='petal_length', data=sns.load_dataset('iris'))


[Link]('Custom Colored Petal Length Distribution')
[Link]()

Using custom palette

4. Adjusting Figure Size and Aspect Ratio

We can adjust the figure size using [Link](figsize=(width,height)) to control the plot's dimensions. This
allows for better customization to fit different presentation or reports.

[Link](figsize=(10, 6))

[Link](x='year', y='passengers', data=sns.load_dataset('flights'))


[Link]('Number of Passengers Over Time')
[Link]()

Output
Adjusting Figure Size and Aspect Ratio

5. Adding Markers to Line Plots

Markers can be added to Seaborn line plots using the marker argument to highlight data points. For
example adding circular markers to the line plot using [Link](x='x', y='y' ,marker='o')

[Link](x='year', y='passengers', data=sns.load_dataset('flights'), marker='o')


[Link]('Number of Passengers Over Time')
[Link]()

Output

Adding marker to lne plot

Visualizing Relationships and Patterns with Seaborn


We’ll see various plots in Seaborn for visualizing relationships, distributions and trends across our dataset.
These visualizations help to find hidden patterns and correlations in datasets with multiple variables.

1. Pair Plots

Pair plots are used explore relationships between several variables by generating scatter plots for every
pair of variables in a dataset along with univariate distributions on the diagonal. This is useful for exploring
datasets with multiple variables and seeing potential correlations.
Syntax:

[Link](data, hue=None)

Parameters:
data: Dataset to plot.
hue: (optional) Categorical variable used for color coding data points.

Returns: An array of Axes objects containing the scatter plot grid and distributions.
Example:

import seaborn as sns


import [Link] as plt

sns.set_style("whitegrid")
custom_palette = sns.color_palette("husl", 8)
sns.set_palette(custom_palette)

data = sns.load_dataset("iris")
[Link](data, hue="species")
[Link]()

Output
Pair Plots

2. Joint Plots

Joint plots combine a scatter plot with the distributions of the individual variables. This allows for a quick
visual representation of how the variables are distributed individually and how they relate to one another.
Syntax:

[Link](x, y, data, kind='scatter')

Parameters:
x, y: Variables to plot.
data: Dataset to plot.
kind: Type of plot to display ('scatter', 'kde', 'reg' etc).

Returns:
An Axes object with the joint plot including scatter plot and distribution plots on the margins.
Example:

import seaborn as sns


import [Link] as plt

data = sns.load_dataset("tips")
[Link](x="total_bill", y="tip", data=data, kind="scatter", color="#008B8B")
[Link]()

Output
Company Explore Tutorials Courses Offline Preparation
About Us POTD Programming ML and Data Centers Corner
Corporate & Communications Address: Legal Practice Languages Science Noida Interview
Privacy Problems DSA DSA and Bengaluru Corner
A-143, 7th Floor, Sovereign Corporate
Tower, Sector- 136, Noida, Uttar Policy Connect Web Placements Pune Aptitude
Pradesh (201305) Careers Blogs Technology Web Hyderabad Puzzles
Contact Us 90% AI, ML & Development Kolkata GfG 160
Registered Address:
Corporate Refund Data Science Data Science System Design
K 061, Tower K, Gulshan Vivante Solution on DevOps Programming
Apartment, Sector 137, Noida, Gautam
Campus Courses CS Core Languages
Buddh Nagar, Uttar Pradesh, 201305
Training Subjects DevOps &
Program GATE Cloud
School GATE
Subjects Trending
Software and Technologies
Tools

@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved

Joint plots

This creates a scatter plot between total_bill and tip with histograms of the individual distributions along
the margins. The kind parameter can be set to 'kde' for kernel density estimates or 'reg' for regression plots.

3. Grid Plot

Grid plots in Seaborn are used to create multiple subplots in a grid layout. Using Seaborn's FacetGrid we
can visualize how variables interact across different categories which makesit easier to compare groups or
conditions within our dataset.

Syntax:

g = [Link](data, col='column_name', row='row_name')


[Link]([Link], 'x', 'y')

Parameters:
data: Dataset to plot.
col, row: Variables for the columns and rows of the grid (categorical variables).
[Link]: The plotting function to apply to each facet.

Returns: A FacetGrid object with the grid of plots.

Example: To use FacetGrid, we first need to initialize it with a dataset and specify the variables that will
form the row, column or hue dimensions of the grid. Here is an example using the tips dataset:

import seaborn as sns


import [Link] as plt

tips = sns.load_dataset("tips")
plot=[Link](tips, col="time", row="sex")
[Link]([Link], "total_bill", "tip")
[Link]()

Output

Grid Plot

Regression Plots: Visualizing Linear Relationships


Seaborn simplifies the process of performing and visualizing regressions specifically linear regressions
which is important for identifying relationships between variables, detecting trends and making predictions.
It supports two primary functions for regression visualization:

regplot(): This function plots a scatter plot along with a linear regression model fit.
lmplot(): This function also plots linear models but provides more flexibility in handling multiple facets
and datasets.

Example: Let’s use a simple dataset to visualize a linear regression between two variables: x (independent
variable) and y (dependent variable).

import seaborn as sns


import [Link] as plt

tips = sns.load_dataset('tips')

[Link](x='total_bill', y='tip', data=tips, scatter_kws={'s':10}, line_kws={'color':'red'})


[Link]()

Output:
Regression Plots

As we explore Seaborn functions and techniques we can create clear, customized and insightful
visualizations that helps us to understand our data better.

Suggested Quiz 5 Questions

Which of the following Seaborn plots is used to visualize the relationship between two numerical variables?

A Bar plot

B Scatter plot

C Box plot

D Heatmap

Login to View Explanation 1/5 < Previous Next >

Comment K kumar… Follow 19

Article Tags: Technical Scripter Data Visualization AI-ML-DS Technical Scripter 2020 +4 More

You might also like