The Wayback Machine - https://web.archive.org/web/20241126224508/https://www.geeksforgeeks.org/introduction-to-seaborn-python/
Open In App

Introduction to Seaborn – Python

Last Updated : 04 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Prerequisite – Matplotlib Library 

Visualization is an important part of storytelling, we can gain a lot of information from data by simply just plotting the features of data. Python provides a numerous number of libraries for data visualization, we have already seen the Matplotlib library in this article we will know about Seaborn Library. 

What is Seaborn

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on top matplotlib library and is also closely integrated with the data structures from pandas.
Seaborn aims to make visualization the central part of exploring and understanding data. It provides dataset-oriented APIs so that we can switch between different visual representations for the same variables for a better understanding of the dataset.

Different categories of plot in Seaborn 

Plots are basically used for visualizing the relationship between variables. Those variables can be either completely numerical or a category like a group, class, or division. Seaborn divides the plot into the below categories – 
 

  • Relational plots: This plot is used to understand the relation between two variables.
  • Categorical plots: This plot deals with categorical variables and how they can be visualized.
  • Distribution plots: This plot is used for examining univariate and bivariate distributions
  • Regression plots: The regression plots in Seaborn are primarily intended to add a visual guide that helps to emphasize patterns in a dataset during exploratory data analyses.
  • Matrix plots: A matrix plot is an array of scatterplots.
  • Multi-plot grids: It is a useful approach to draw multiple instances of the same plot on different subsets of the dataset.

Installation of Seaborn Library 

For Python environment : 

pip install seaborn

For conda environment : 

conda install seaborn

Dependencies for Seaborn Library 

There are some libraries that must be installed before using Seaborn. Here we will list out some basics that are a must for using Seaborn. 

  • Python 3.6 or higher 
  • numpy (>= 1.13.3) 
  • scipy (>= 1.0.1)
  • pandas (>= 0.22.0)
  • matplotlib (>= 2.1.2) 

However, we must note that if try to use Seaborn 

Some basic plots using seaborn

Histplot:  Seaborn Histplot is used to visualize the univariate set of distributions(single variable). It plots a histogram, with some other variations like kdeplot and rugplot. The Histplot function takes several arguments but the important ones are

  • data: This is the array, series, or dataframe that you want to visualize. It is a required parameter.
  • x: This specifies the column in the data to use for the histogram. If your data is a dataframe, you can specify the column by name.
  • y: This specifies the column in the data to use for the histogram when you want to create a bivariate histogram. By default, it is set to None, meaning that a univariate histogram will be plotted.
  • bins: This specifies the number of bins to use when dividing the data into intervals for plotting. By default, it is set to “auto”, which uses an algorithm to determine the optimal number of bins.
  • kde: This parameter controls whether to display a kernel density estimate (KDE) of the data in addition to the histogram. By default, it is set to False, meaning that a KDE will not be plotted.
Python3
import numpy as np
import seaborn as sns

sns.set(style="white")

# Generate a random univariate dataset
rs = np.random.RandomState(10)
d = rs.normal(size=100)

# Plot a simple histogram and kde
sns.histplot(d, kde=True, color="m")

Output: 

Histogram with seaborn 

Distplot: Seaborn distplot is used to visualize the univariate set of distributions(Single features) and plot the histogram with some other variations like kdeplot and rugplot.

The function takes several parameters, but the most important ones are:

  • a: This is the array, series, or list of data that you want to visualize. It is a required parameter.
  • bins: This specifies the number of bins to use when dividing the data into intervals for plotting. By default, it is set to “auto”, which uses an algorithm to determine the optimal number of bins.
  • kde: This parameter controls whether to display a kernel density estimate (KDE) of the data in addition to the histogram. By default, it is set to True, meaning that a KDE will be plotted.
  • hist: This parameter controls whether to display the histogram of the data. By default, it is set to True, meaning that a histogram will be plotted.
Python
import numpy as np
import seaborn as sns

sns.set(style="white")

# Generate a random univariate dataset
rs = np.random.RandomState(10)
d = rs.normal(size=100)

# Define the colors to use
colors = ["r", "g", "b"]

# Plot a histogram with multiple colors
sns.distplot(d, kde=True, hist=True, bins=10,
             rug=True,hist_kws={"alpha": 0.3,
                                "color": colors[0]},
             kde_kws={"color": colors[1], "lw": 2},
             rug_kws={"color": colors[2]})

Output:

Distplot using seaborn

Distplot using seaborn 

Note: The distplot function has been depreciated in the newer version of the Seaborn Library 

Lineplot: The line plot is one of the most basic plots in the seaborn library. This plot is mainly used to visualize the data in the form of some time series, i.e. in a continuous manner.

Python3
import seaborn as sns


sns.set(style="dark")
fmri = sns.load_dataset("fmri")

# Plot the responses for different\
# events and regions
sns.lineplot(x="timepoint",
             y="signal",
             hue="region",
             style="event",
             data=fmri)

Output : 

Lineplot using seaborn 


Lmplot:  The lmplot is another most basic plot. It shows a line representing a linear regression model along with data points on the 2D space and x and y can be set as the horizontal and vertical labels respectively.

Python3
import seaborn as sns

sns.set(style="ticks")

# Loading the dataset
df = sns.load_dataset("anscombe")

# Show the results of a linear regression
sns.lmplot(x="x", y="y", data=df)

Output : 

Lmplot using seaborn 


 



Previous Article
Next Article

Similar Reads

An Introduction To The Seaborn Objects System
Seaborn has long been a popular library for data visualization in Python, known for its ease of use and beautiful default styles. However, with the release of Seaborn version 0.12, a new interface called the Seaborn objects system was introduced. This new system, inspired by the Grammar of Graphics, provides a more flexible and modular approach to
7 min read
Horizontal Boxplots with Seaborn in Python
Prerequisite: seaborn The Boxplots are used to visualize the distribution of data which is useful when a comparison of data is required. Sometimes, Boxplot is also known as a box-and-whisker plot. The box shows the quartiles of dataset and whiskers extend to show rest of the distribution. In this article, we are going to implement the Horizontal bo
1 min read
How to Show Mean on Boxplot using Seaborn in Python?
A boxplot is a powerful data visualization tool used to understand the distribution of data. It splits the data into quartiles, and summarises it based on five numbers derived from these quartiles: median: the middle value of data. marked as Q2, portrays the 50th percentile.first quartile: the middle value between "minimum non-outlier" and median.
2 min read
Boxplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated into the data structures from pandas. Box Plot A box plot helps to maintain the distribut
5 min read
Python Seaborn - Catplot
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major problems faced by Matplotlib; the problems are? Default Matplotlib parametersWorking with data frames As Seaborn compliments and extends Matplotlib, t
5 min read
Python - seaborn.jointplot() method
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major problems faced by Matplotlib; the problems are ? Default Matplotlib parametersWorking with data frames As Seaborn compliments and extends Matplotlib,
3 min read
Python - seaborn.factorplot() method
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas. seaborn.factorplot() method seaborn.factorplot() meth
5 min read
Python - seaborn.lmplot() method
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas. seaborn.Implot() method seaborn.lmplot() method is us
7 min read
Countplot using seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas. Seaborn.countplot() seaborn.countplot() method is use
7 min read
Seaborn.barplot() method in Python
Seaborn is a Python data visualization library based on Matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. There is just something extraordinary about a well-designed visualization. The colors stand out, the layers blend nicely together, the contours flow throughout, and the overall package n
4 min read
Lineplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides default styles and color palettes to make statistical plots more attractive. It is built on the top of the matplotlib library and is also closely integrated into the data structures from pandas. LineplotVisual representation of a dataset must be cho
4 min read
Barplot using seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas. Seaborn.barplot() seaborn.barplot() method is used to
6 min read
Scatterplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated into the data structures from pandas. Scatter Plot Scatterplot can be used with several s
4 min read
Violinplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated into the data structures from pandas. Violin Plot A violin plot plays a similar activity
7 min read
Swarmplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of the matplotlib library and also closely integrated into the data structures from pandas. Swarm Plot Seaborn swarmplot is probably simila
6 min read
Data Visualisation in Python using Matplotlib and Seaborn
It may sometimes seem easier to go through a set of data points and build insights from it but usually this process may not yield good results. There could be a lot of things left undiscovered as a result of this process. Additionally, most of the data sets used in real life are too big to do any analysis manually. This is essentially where data vi
14 min read
Python - seaborn.pairplot() method
Prerequisite: Seaborn Programming Basics Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major issues while working with Matplotlib: Default Matplotlib parametersWorking with data frames As Seaborn compli
2 min read
Python - seaborn.FacetGrid() method
Prerequisite: Seaborn Programming Basics Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major problems faced by Matplotlib; the problems are ? Default Matplotlib parametersWorking with data frames As Sea
3 min read
Python - seaborn.PairGrid() method
Prerequisite: Seaborn Programming Basics Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major problems faced by Matplotlib; the problems are ? Default Matplotlib parametersWorking with data frames As Sea
3 min read
seaborn.lineplot() method in Python
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. The colors stand out, the layers blend nicely together, the contours flow throughout, and the overall package not only has a nice aesthetic quality, but it provides meaningful insights t
2 min read
Python - seaborn.regplot() method
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major problems faced by Matplotlib; the problems are ? Default Matplotlib parametersWorking with data frames As Seaborn compliments and extends Matplotlib,
3 min read
Python - seaborn.pointplot() method
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas. seaborn.pointplot() :This method is used to show poin
3 min read
Python - seaborn.residplot() method
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas. seaborn.residplot() : This method is used to plot the
2 min read
Python - seaborn.boxenplot() method
Prerequisite : Fundamentals of Seaborn Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. There is just something extraordinary about a well-designed visualization. The colors stand out, the layers blend nicely together, the contours flo
3 min read
Python - seaborn.swarmplot() method
Prerequisite : Fundamentals of Seaborn Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. There is just something extraordinary about a well-designed visualization. The colors stand out, the layers blend nicely together, the contours flo
3 min read
Stripplot using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on top of the matplotlib library and also closely integrated into the data structures from pandas. Strip plot A strip plot is drawn on its own. It is
5 min read
How To Place Legend Outside the Plot with Seaborn in Python?
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Basically, it helps us stylize our basic plot made using matplotlib. Moreover, it also provides us different plotting techniques to ease our Exploratory Data Analysis(EDA). With these pl
2 min read
How to Make Grouped Violinplot with Seaborn in Python?
This article depicts how to make a grouped violinplot with Seaborn in python. Violinplot is a great way of visualizing the data as a combination of the box plot with the kernel density plots to produce a new type of plot. For this article, we will be using the iris dataset to plot data. This comes inbuilt in seaborn and can be loaded with the load_
3 min read
How to Make Horizontal Violin Plot with Seaborn in Python?
In this article, we are going to plot a horizontal Violin plot with seaborn. We can use two methods for the Drawing horizontal Violin plot, Violinplot() and catplot(). Method 1: Using violinplot() A violin plot plays a similar activity that is pursued through whisker or box plot do. As it shows several quantitative data across one or more categoric
3 min read
Horizontal Boxplots with Points using Seaborn in Python
Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated into the data structures from pandas.Seaborn aims to make visualization of the central pa
3 min read
Article Tags :
Practice Tags :
three90RightbarBannerImg