0% found this document useful (0 votes)
19 views35 pages

Unit 5 Seaborn Visualization

The document provides an overview of data visualization using the Seaborn library in Python, highlighting its advantages over Matplotlib, such as simplified syntax and better integration with Pandas. It covers various types of visualizations, including statistical relationships, categorical data, and data distributions, along with installation instructions and example syntax. Additionally, it includes quizzes to test understanding of the material presented.

Uploaded by

rohini.d.patel
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)
19 views35 pages

Unit 5 Seaborn Visualization

The document provides an overview of data visualization using the Seaborn library in Python, highlighting its advantages over Matplotlib, such as simplified syntax and better integration with Pandas. It covers various types of visualizations, including statistical relationships, categorical data, and data distributions, along with installation instructions and example syntax. Additionally, it includes quizzes to test understanding of the material presented.

Uploaded by

rohini.d.patel
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
You are on page 1/ 35

Data Visualization Using Seaborn

Unit 5
Data Visualization
Using Seaborn
Data Visualization Using Seaborn

Disclaimer
The content is curated from online/offline resources and used for educational purpose only
Data Visualization Using Seaborn

Click here

Reference link
Data Visualization Using Seaborn

Learning Objectives
• Why should you use Seaborn versus matplotlib?
• Introduction to Seaborn
• Seaborn Vs Matplotlib
• Seaborn Installation
• Data Visualization using Seaborn
• Visualizing Statistical Relationship
• Visualizing Distribution of Data
Data Visualization Using Seaborn

Why should you use Seaborn Versus Matplotlib?


• Seaborn is more at ease with Pandas data frames and
uses simple methods to create beautiful graphics in
Python.

• Matplotlib works efficiently with data frames and arrays,


treats figures and axes as objects, and contains various
stateful APIs for plotting.
V/S
Data Visualization Using Seaborn

What is Seaborn?
• Seaborn is a Python library used to generate statistical
graphics.
• It is built on top of matplotlib and closely integrates with
pandas data structures.
• Seaborn assists you in discovering and understanding
your data.
Data Visualization Using Seaborn

V/S
• In Seaborn, there are numerous patterns and • Matplotlib generates simple graphs such as bar
graphs for data visualisation. It uses interesting graphs, histograms, pie charts, scatter plots, lines,
themes and aids in the integration of all data into a and other data visualisations.
single plot. • It employs relatively complicated and extensive
• It has relatively simple syntax, making it simpler to syntax.
learn and comprehend.
• Matplotlib is a Python graphics package for data
• Seaborn is more comfortable with Pandas data
frames. It utilizes simple sets of techniques to visualization and integrates nicely with Numpy and
produce lovely images in Python. Pandas.
Data Visualization Using Seaborn

Installing Seaborn
To install the latest release of seaborn, you can use pip:

$ pip install seaborn

You can also use conda to install the latest version of seaborn:

$conda install seaborn


Data Visualization Using Seaborn

Data Visualization using Seaborn


• The presentation of data in pictorial form is known as data
visualization.
• Let’s get started! We have divided this implementation section
into three categories:

Visualizing statistical relationships

Plotting categorical data

Visualizing Distributions Of Data


Data Visualization Using Seaborn

1.Visualizing Statistical Relationships


The process of determining how variables in a dataset relate to one another and how those
relationships are affected by other variables is known as statistical analysis.
Using seaborn to generate the below plots:

1. Scatterplot
2. Lineplot
3. Regplot
4. Heatmap
5. Boxplot
6. Violinplot
Data Visualization Using Seaborn

Scatter Plot
• The scatter plot is a standard statistical visualisation tool.
The joint distribution of two variables is represented as a
cloud of points, with each point representing a dataset
observation.

Syntax: seaborn.scatterplot(x=None, y=None)


Parameters:
x, y: Input data variables that should be numeric.
Returns: This method returns the Axes object with the
plot drawn onto it.
# plotting
seaborn.scatterplot(data[‘total_bill'],data[‘tip'])
Data Visualization Using Seaborn

Line Plot
The line plot is the most commonly used plot for
drawing a relationship between x and y, with the option
of several semantic groupings.

Syntax : sns.lineplot(x=None, y=None)


Parameters:
x, y: Input data variables; must be numeric. Can pass
data directly or reference columns in data.
# plotting lineplot
sns.lineplot( data[‘total_bill'], data[‘tip'])
Data Visualization Using Seaborn

Reg Plot
Plot data and a linear regression model fit.

Syntax : sns.regplot(x=None, y=None, data=None)

Parameters:
x, y: Input data variables; must be numeric. Can pass
data directly or reference columns in data.
Data Visualization Using Seaborn

Lab 1 Visualizing statistical relationships-


Scatterplot Line plot and Reg plot
Data Visualization Using Seaborn

Heat Map
A heat map is a two-dimensional representation of data
in which values are represented by colors.
Heatmap helps to correlate the different features in
order to take the decision.

# plotting heatmap
sns.heatmap(tips.corr())
Syntax : sns.lineplot(x=None, y=None)
Parameters:
x, y: Input data variables; must be numeric. Can pass
data directly or reference columns in data.
Data Visualization Using Seaborn

Box Plot
A box plot (or box-and-whisker plot) is a visual
representation of numerical data groups portrayed through
their quartiles versus continuous/categorical data.
Syntax:
seaborn.boxplot(x=None, y=None, hue=None,
data=None)
Parameters:
•x, y, hue: Inputs for plotting long-form data.
•data: Dataset for plotting. If x and y are absent, this is
interpreted as wide-form.

sns.boxplot( data['Age'] )
Data Visualization Using Seaborn

Violin Plot
• A violin plot functions similarly to a box plot. It depicts the
distribution of quantitative data across multiple levels of
one (or more) categorical variable, allowing those
distributions to be compared.

• sns.violinplot(x="day", y="total_bill",
data=t,palette='rainbow')
Data Visualization Using Seaborn

Lab 1 Visualizing statistical relationships-


Heatmap, Boxplot and Violin plot
Data Visualization Using Seaborn

2. Plotting Categorical Data


• A categorical variable (also known as a nominal variable) has two or more categories but no inherent
ordering of the categories.
• let’s discuss using seaborn to plot categorical data-

Swarm
striplot
plot

Violin Count
plot plot
Data Visualization Using Seaborn

Count Plot
• This is similar to barplot except that the estimator explicitly counts the number of occurrences. As a
result, we only pass the x value. The command for making a countplot is:
• sns.countplot(x='sex',data=t)
Data Visualization Using Seaborn

Strip Plot AND Swarm Plot


The stripplot() will create a scatterplot with one The swarmplot() function is similar to stripplot(),
categorical variable. but the points are adjusted so that they do not
overlap (only along the categorical axis).
sns.stripplot(x="day", y="total_bill", data=t)
sns.swarmplot(x="day", y="total_bill", data=t)
Data Visualization Using Seaborn

Lab 2 Plotting Categorical Data


Data Visualization Using Seaborn

3. Visualizing Distributions of Data

histplotplot

displot(Distributions) kdeplot

ecdfplot
Data Visualization Using Seaborn

1. Histograms
• One of the most popular methods for visualising a distribution is the histogram. This method is used by
default in the histplot()-based function displot(). A histogram is a bar plot in which the axis representing
the data variable is divided into discrete bins, and the height of the corresponding bar represents the
number of observations falling within each bin:

ds = seaborn.load_dataset(“ds")
seaborn.displot(ds, x="flipper_length_mm")

* ds is a dataset
Data Visualization Using Seaborn

2. Kernel Density Estimation (KDE) Plot


By binning and counting observations, a histogram attempts to approximate the underlying probability
density function that produced the data. The same issue is addressed differently by kernel density
estimation (KDE). A KDE plot produces a continuous density estimate by smoothing the observations with
a Gaussian kernel as opposed to using discrete bins:

seaborn.displot(ds, x="flipper_length_mm",
kind="kde")
Data Visualization Using Seaborn

2. Kernel Density Estimation (KDE) Plot


Choosing the smoothing bandwidth Conditioning on other variables

seaborn.displot(ds, x="flipper_length_mm", seaborn.displot(ds, x="flipper_length_mm“,


kind="kde“, bw_adjsut =.25) hue=“species” kind="kde“)
Data Visualization Using Seaborn

Lab 3 Visualizing Distributions Of Data - Kernel


density estimation (KDE) plot
Data Visualization Using Seaborn​

Summary
Seaborn Advantages over Matplotlib: Simplified syntax and high-level interface for
creating aesthetically pleasing visualizations.

Introduction to Seaborn: Python data visualization library based on Matplotlib, designed


for creating informative and attractive statistical graphics.

Visualizing Statistical Relationship: Seaborn facilitates visualizing statistical relationships


using functions like Scatter plot, Line plot, heat map and so on.

Visualizing Distribution of Data: Seaborn offers a variety of plots to visualize data


distribution, including histograms and kernel density plots. Functions like distplot and
kdeplot reveal insights into data spread and central tendencies.
Data Visualization Using Seaborn

Quiz​
1. What is a key advantage of using Seaborn over Matplotlib?

a) Seaborn offers lower-level control for customization.


b) Seaborn provides built-in support for 3D visualizations.
c) Seaborn simplifies syntax for complex plots and attractive statistical graphics.
d) Seaborn requires separate installation from Matplotlib.

Answer: c) Seaborn simplifies syntax for complex plots and attractive statistical graphics.
Data Visualization Using Seaborn

Quiz​
2. What this trend line indicate?

a) The line plot depicts the trend of passenger


numbers over the years.
b) There is a consistent overall increase in the
number of passengers from year to year.
c) There is a consistent overall decrease in the
number of passengers from year to year.
d) Both A & B

Answer: d) Both A & B


Data Visualization Using Seaborn

Quiz​
3. What this plot indicate?

a) The histograms depict the distribution of


passenger counts.
b) They show that the most common range of
passenger counts is around 200-300, followed by
400-500.
c) Both A & B.
d) This is a left side skewed distribution.

Answer: c) Both a & b


Data Visualization Using Seaborn

Quiz​
4. Which Seaborn function is specifically used to visualize statistical relationships involving linear
regression?

a) Line Plot
b) Scatter Plot
c) Heatmap
d) All of the above

Answer: d) All of the above


Data Visualization Using Seaborn

Quiz​
5. Which type of visualization does Seaborn's distplot function primarily help in creating?

a) 3D scatter plots
b) Bar charts
c) Histograms and kernel density plots
d) Heatmaps

Answer: c) Histograms and kernel density plots


Data Visualization Using Seaborn

References
• https://seaborn.pydata.org/tutorial/relational.html
• https://www.analyticsvidhya.com/blog/2019/09/comprehensive-data-visualization-guide-seaborn-python/
• https://datahack.analyticsvidhya.com/contest/enigma-codefest-machine-learning-1/#ProblemStatement
• https://datahack.analyticsvidhya.com/contest/wns-analytics-hackathon-2018-1/#ProblemStatement
• https://towardsdatascience.com/data-visualization-using-seaborn-fc24db95a850
• https://www.freepik.com/
Data Visualization Using Seaborn

Thank you...!

You might also like