# Seaborn : A data Visualization Library

## Introduction:

Hi there! In this blog, we’ll explore one of the most popular Python libraries for data visualization — ***"Seaborn"***. If you’ve ever looked at raw data and thought, “How do I make this understandable?”, then Seaborn is your friend.

### What is Seaborn?

Seaborn is a Python data visualization library built on top of Matplotlib. It’s designed to make it easier to create beautiful and informative plots. While Matplotlib is powerful, it can sometimes feel clunky or require extra lines of code.

### So, why use Seaborn instead?

* **Cleaner syntax** → A graph that might take 3–4 lines in Matplotlib can often be done in just 1 line with Seaborn.
    
* **Better visuals by default** → Seaborn’s default styles are much more appealing and professional looking than Matplotlib’s.
    
* **Flexibility** → Like Matplotlib, you can customize almost everything, but with less effort.
    

---

## Installation and Setup

To use Seaborn, we first need to have it on our system. You can install it using:

```plaintext
pip install seaborn
```

If you already have it installed, you can simply import it. The most commonly used alias is "sns":

```plaintext
import seaborn as sns
```

You can also import other libraries depending on your project. I personally like to import the base libraries on which my current working library is built, just in case. For example, since Seaborn is built on Matplotlib, you might also import:

```plaintext
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
```

Most of the time, you’ll need Pandas and NumPy to work with datasets alongside Seaborn.

---

## Datasets in Seaborn

The best way to get started with Seaborn is by working on datasets. One of the reasons Seaborn is so beginner-friendly is that it provides built-in datasets, so you don’t have to worry about finding external files, you can access them directly and for free.

To see all the datasets available in Seaborn, you can use:

```plaintext
sns.get_dataset_names()
```

This will return a list of available datasets, from which you can choose one that you like. For this blog, I’ll select a few datasets according to my preference so we can explore Seaborn effectively, but you are free to pick any dataset you like.

To load a dataset and save it in a variable, simply use:

```plaintext
tips = sns.load_dataset("tips")
fmri = sns.load_dataset("fmri")
titanic = sns.load_dataset("titanic")
flights = sns.load_dataset("flights")
iris = sns.load_dataset("iris")
```

After running these commands, the datasets are loaded into memory as Pandas DataFrames, and you can start working with them right away.

---

## Seaborn Plotting Functions

Before jumping into how to plot graphs in Seaborn and the different types available, it’s important to understand the two main plotting functions Seaborn provides:

1. ***Axis-level functions***
    
2. ***Figure-level functions***
    

At first, both might look like they do the same thing (that’s what confused me too when I started). But here’s the simple breakdown:

### 1\. Axis-level Functions

* These functions draw plots directly on a single Matplotlib Axes (basically one x-y coordinate system).
    
* Any customization you do applies only to that one plot area.
    
* Limitation: You can’t create subplots (multiple plots in one figure) with them.
    

***By default:***

* The plot has a rectangular aspect ratio(but you can adjust it).
    
* Legends usually stay inside the plot area since control is limited to the axes.
    

### 2\. Figure-level Functions

* These work at the entire figure level, meaning they can handle multiple plots (subplots) automatically.
    
* You don’t have to create subplots manually — Seaborn manages the layout for you.
    

***By default:***

* The overall figure is more “squarish”(customizable)
    
* Legends are placed outside the plot, since it controls the whole figure.
    

---

## Types of plots in seaborn

There are about 6 types of plot in seaborn which has further classification, that we will cover, so the structure of classification is :

1. **Relational Plot**
    
    * Scatter Plot
        
    * Line Plot
        
2. **Distribution Plot**
    
    * Histogram
        
    * KDEplot (Kernal Density Estimation plot)
        
    * Rugplot
        
3. **Categorical Plot**
    
    * Categorical Scatter Plot
        
        * Stripplot
            
        * Swarmplot
            
    * Categorical Distribution Plots
        
        * Boxplot
            
        * Violinplot
            
    * Categorical Estimate Plot - for Central Tendency
        
        * Barplot
            
        * Countplot
            
        * Pointplot
            
4. **Regression Plot**
    
    * Regplot
        
    * Lmplot
        
5. **Matrix Plot**
    
    * Heatmap
        
    * Clustermap
        
6. **Multiplots**
    
    * Joint Plot
        
    * Pair Plot
        
    * FaceGrid
        

We will begin up with relational plot and will go to multiplot, trying to unravel seaborn itself

---

## 1\. Relational Plot

Relational plots are used to visualize relationships between two (or more) variables. In simple terms, they help us perform bivariate analysis(seeing how one column relates to another).

As mentioned earlier, Seaborn has two kinds of plotting functions, both of which can be used for relational plots:

* ***Figure-level function*** → `relplot()`
    
* ***Axis-level functions*** → `scatterplot()`, `lineplot()`
    

Let’s go through them step by step:

### (i) Scatter Plot

Scatter plots show the relationship between two numerical variables by displaying data points on an x–y plane. Each point (marker) represents one observation, positioned according to its values on the x and y axes.

*Example:* We’ll use the tips dataset and plot the relationship between the total bill and the tip.

```plaintext
# Axis-level function
sns.scatterplot(data=tips, x="total_bill", y="tip")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760848827878/911b8b87-6e73-4a24-80e7-427b656416d4.png align="center")

```plaintext
# Figure-level function
sns.relplot(data=tips, x="total_bill", y="tip", kind="scatter")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760848907973/14ac8883-9d54-4955-b28a-efc0a49f0459.png align="center")

Seaborn also makes it super easy to add extra dimensions to your visualization:

* ***hue*** → color points by a category
    
* ***style*** → change marker shapes by a category
    
* ***size*** → scale marker size by a numeric or categorical variable
    

```plaintext
sns.relplot(data=tips, x="total_bill", y="tip", hue="sex", style="time", size="size", kind="scatter")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760848935157/8434171f-d4f7-4be4-adda-0773bccfa809.png align="center")

### (ii) Line Plot

Line plots are designed to show the relationship between two continuous variables, often over time or some sequential order. They’re perfect for spotting trends or changes.

*Example 1 : (Simple, made-up data)*

```plaintext
days = ["Mon","Tues","Wed","Thus","Fri","Sat","Sun"]
temperature = [30,32,31,29,28,27,26]
temperature_df = pd.DataFrame({"days": days, "temperature": temperature})

# Axis-level function
sns.lineplot(data=temperature_df ,x="days", y="temperature")

# Figure-level function
sns.relplot(data=temperature_df, x="days", y="temperature", kind="line")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849157811/c1a78753-1af0-48a1-9173-22b942f95f5d.png align="center")

*Example 2 : (Using fmri dataset)*

```plaintext
# Adding more info
sns.relplot(data=fmri, x="timepoint", y="signal", hue="event", style="region", size="subject", kind="line")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849175784/45cf1c8a-3d5f-4c4d-8a01-bef2ce62508d.png align="center")

***Some tips***:

* We use ***scatter plots*** when our data points are independent observations (e.g., bills vs tips).
    
* We use ***line plots*** when our x-axis has some order (like time, age, or sequence) and you want to visualize it.
    

---

## 2\. Distribution Plot

Distribution plot is used to perform univariate analysis which means it focuses on a single column, it also helps in identifying the range of observation, distribution, and the central tendency(mean, median, mode) in the data. It can also be use to answer questions like "Is the data bimodal(have many peaks)" or "Are there outliers(extreme values)?"

Just like relational plot, distribution plot also have both plotting functions, given as:

* ***Figure level funciton*** -&gt; `displot()`
    
* ***Axis level functions*** -&gt; `histplot()`, `kdeplot()`, `rugplot()`
    

### (i) Histogram/Histplot

Histogram is a bar like chart that shows the distribution of numerical data by dividing the data into "bins" and then displaying the count or density of observations falling within each bin using bars.

We can specify the bin size explicitly or can leave it to the default settings, the plotting is done as follow:

```plaintext
# Axis-level function
sns.histplot(data=tips, x="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849219630/3f5e5250-48c1-48c1-b779-96f25cd8315a.png align="center")

```plaintext
# Figure level function
sns.displot(data=tips, x="total_bill", kind="hist")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849241270/d34aefe8-cf39-4f59-a466-30508573c00c.png align="center")

***element="step"*** -&gt; shows just the border/outline of each histogram

```plaintext
sns.displot(data=tips, x="tip", hue="sex", element="step", kind="hist")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849290816/59ec0aa0-23c3-4076-9e59-5b5085b31d3f.png align="center")

Now here’s something interesting, histograms are part of distribution plots which means they’re used for univariate analysis. But there’s a cool twist, histograms also have a variant that works for bivariate analysis, and is called the bivariate histogram.

**Bivariate Histogram** : Think of it as a 3D-style plot that shows the frequency distribution of two variables at once. The data gets divided into rectangles (bins) across both axes, and the color shade tells you how many points fall inside each rectangle:

* *Darker color* → more data points (higher density)
    
* *Lighter color* → fewer data points (lower density)
    

```plaintext
# Axis-level function
sns.histplot(data=tips, x="total_bill", y="tip")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849672471/4987c3ea-a850-4393-8d13-c0277ee1dee8.png align="center")

```plaintext
# Figure-level function
sns.displot(data=tips, x="total_bill", y="tip", kind="hist")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849702515/5bad98d3-2571-49a2-99f6-1e0c88175439.png align="center")

### (ii) KDEplot

A KDE (Kernel Density Estimate) plot is another way of looking at distributions. Instead of dividing the data into discrete bins like a histogram, KDE creates a smooth curve that represents the probability density function (usually using a Gaussian kernel).

Think of it like this: a small bell-shaped curve is placed on each data point, and then all these curves are added together to form one smooth and continuous line.

```plaintext
# Axis-level function
sns.kdeplot(data=tips, x="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849505692/fdd0d939-ffed-4c27-995c-a39bc0f2669a.png align="center")

```plaintext
# fill = fills the area under the curve with color
sns.kdeplot(data=tips, x="total_bill", hue="sex", fill=True)
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849533018/b9f42080-b869-4df5-9951-070f4eef1f0f.png align="center")

***height*** → controls overall figure size

***aspect*** → controls the width-to-height ratio

```plaintext
# Figure-level function
sns.displot(data=tips, x="total_bill", hue="sex", fill=True, height=10, aspect=2, kind="kde")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849615065/15feab74-1182-4d04-919a-26d948088891.png align="center")

**Bivariate KDEplot** : Just like a bivariate histogram, but smoother! Here, instead of plotting two discrete variables, KDE smooths the (x, y) observations with a 2D Gaussian distribution. The result is a soft, continuous density region instead of blocky bins.

```plaintext
# Axis-level function
sns.kdeplot(data=tips, x="total_bill", y="tip")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849729141/97a9a37c-30ea-4b0d-9799-29720f8cfbe0.png align="center")

```plaintext
# Figure level function
sns.displot(data=tips, x="total_bill", y="tip", hue="sex", fill=True, kind="kde")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849753949/170e657d-b170-44bb-a9a0-16d4e0cbeede.png align="center")

### (iii) Rugplot

A Rug plot shows the marginal distribution of individual data points by drawing small ticks (rugs) along the x or y axis. We can think of it as a subtle way to show where each observation lies, it is often used alongside KDE or histogram plots to give a clearer sense of data concentration.

```plaintext
sns.kdeplot(data=tips, x="total_bill")
sns.rugplot(data=tips, x="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849882458/2c9f1591-2ccd-4c78-8c5c-8219e6cac026.png align="center")

Here, the rug marks on the x-axis represent each individual data point, the denser the ticks, the more frequent the values in that range.

*Note* : We can’t directly use a figure-level function (displot) for rug plots, it’ll throw an error, but here’s a workaround :

```plaintext
sns.displot(data=tips, x="total_bill", kind="kde")
sns.rugplot(data=tips, x="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849899760/5a2e1c92-23b9-4eba-8f60-f2cd6a267a6e.png align="center")

***Some tips***:

* We can think of ***histogram*** as "blocks"(bar like bins) whereas ***KDE*** as a "smooth curve" drawn over those blocks, both plots are used for distribution but do it in different styles.
    

To understand it better, we can try plotting them together:

```plaintext
sns.histplot(data=tips, x="total_bill", kde=True)
```

* ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760849981273/ef09c6cc-aefd-4141-afc0-a27957f98f09.png align="center")
    
    When we plot one variable, it's ***univariate*** and when we plot two variable at the same time, it is called ***bivariate***, So basically ***one axis = univariate*** and ***two axes = bivariate***
    

---

## 3\. Categorical plot

Categorical plots are used to show the relationship between one or more categorical variables and a numerical variable or simply to compare how numerical data varies across different categories.

***Figure-level function*** -&gt; `catplot()`

### (1) Categorical Scatter plot

A categorical scatter plot usually involves one categorical column and one numerical column.

***Axis-level functions*** -&gt; `stripplot()`, `swarmplot()`

#### (i) Stripplot

A Stripplot is basically a scatter plot that spreads data points along a single axis to show how a numeric variable is distributed across categories. It’s simple, clean, and works really well when your large datasets.

```plaintext
# Axis-level function
sns.stripplot(data=tips, x="day", y="total_bill", hue="sex")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850021499/0722988f-269d-4189-ba4b-a226511ce2ea.png align="center")

***jitter=True/specified amount(like 0.2)*** -&gt; It adds random displacement/noise along the categorical axis, helping separate overlapping dots horizontally. Just remember, jitter only works with stripplot.

```plaintext
# Function-level function
sns.catplot(data=tips, x="day", y="total_bill", hue="sex", jitter=0.2, kind="strip")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850085677/8df37bae-9647-4635-bac4-6a22e4d12c46.png align="center")

#### (ii) Swarmplot

A Swarmplot is similar to a stripplot, but it automatically arranges the points so that they don’t overlap, giving a clearer picture of how values are distributed. Just one catch, it’s not the best choice for very large datasets also a little fun fact Swarmplot is also called a “beeswarm” plot because of its appearance.

```plaintext
# Axis-level function
sns.swarmplot(data=tips, x="day", y="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850403664/e004a9bd-9a0a-4c3e-a5eb-5de06029c095.png align="center")

```plaintext
# Function-level function
sns.catplot(data=tips, x="day", y="total_bill", hue="sex", kind="swarm")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850469503/d564ab22-1510-441a-a0fc-99e252b19c0c.png align="center")

### (2) Categorical Distribution Plots

A categorical distribution plot shows how data points are distributed across discrete categories, in other words, it helps you see how your numerical values vary for each category.

***Axis-level function*** -&gt; `boxplot()`, `violinplot()`

#### (i) Box plot

A Boxplot is a classic way to visualize data distribution based on the five number summary(minimum, first quartile \[Q1\], median \[Q2\], third quartile \[Q3\], and maximum).

Boxplots can help answer questions like:

* Are there any outliers (extreme values)?
    
* Is the data symmetric or skewed?
    
* How tightly is the data grouped together?
    

```plaintext
# Axis-level function
sns.boxplot(data=tips, x="day", y="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850629232/07f230d5-c8e0-45e7-ad9a-a202506b8026.png align="center")

```plaintext
# Figure-level function
sns.catplot(data=tips, x="day", y="total_bill", hue="sex", kind="box")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850769025/626e05d6-c44f-4f89-9aaf-2d08b584af6f.png align="center")

```plaintext
# Single boxplot
sns.boxplot(data=tips, y="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850790486/e5862fc7-71c9-4e05-8c6b-d4289651936a.png align="center")

#### (ii) Violin plot

Violin plot shows the distribution of numeric data using density curves. The width of each curve represents the frequency of data points(wider means more data in that range). In simple terms, we can think of it as a mix between a boxplot and a KDE plot as it combines both the summary statistics and the shape of the distribution.

```plaintext
# Axis-level function
sns.violinplot(data=tips, x="day", y="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850831814/72aff027-9f40-4cad-b0d7-56c9329803af.png align="center")

```plaintext
# Figure-level function
sns.catplot(data=tips, x="time", y="total_bill", hue="sex", kind="violin")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850866712/7fd5de46-13a0-4af7-a32b-56bc1c200d79.png align="center")

***split=True*** -&gt; Combines two violin plots into one, where each side of the “violin” represents a different category. It’s a neat way to compare two groups side by side.

```plaintext
sns.catplot(data=tips, x="day", y="total_bill", hue="sex", split=True, kind="violin")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850882747/7e31a778-b68e-4b25-99ba-22e6bd1df49d.png align="center")

*Note* : split=True only works when you have a binary hue variable(two categories).

### (3) Categorical Estimate Plot

***Axis-level function*** -&gt; `barplot()`, `pointplot()`, `countplot()`

#### (i) Bar plot

A Bar plot is used to represent an estimate of central tendency (like mean or median) for a numerical variable, using the height of rectangular bars. It can also include error bars (the small vertical lines on top of bars) to show the uncertainty or variation in the estimate.

Bar plots are especially handy when you want to compare a numerical variable across different categories of a categorical variable.

```plaintext
# Axis-level function
sns.barplot(data=tips, x="sex", y="total_bill", hue="day")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850918527/8008cc1b-d303-4b99-aec0-d0b0abcba68d.png align="center")

***ci=None*** -&gt; Used to remove the error bar for a cleaner look

```plaintext
# Figure-level function
sns.catplot(data=tips, x="day", y="total_bill", hue="sex", ci=None, kind="bar")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850972895/e096100f-a956-4e6d-9141-548a9cfa53d7.png align="center")

***estimator*** -&gt; This parameter lets us choose which aggregate function to apply to your data (like median, max, min, sum, len, etc.). By default, Seaborn uses the mean.

Here’s an example using "min" as the estimator, but you can try out others too:

```plaintext
sns.catplot(data=tips, x="sex", y="total_bill", hue="sex", estimator=np.min, kind="bar")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760850989312/9679ca41-d521-4694-add0-2f67a029e874.png align="center")

#### (ii) Point plot

A Point plot represents the central tendency of a numeric variable across different levels of a categorical variable. The points are often connected by lines, making it easier to spot comparisons or trends between categories and the vertical error bars show the variation or uncertainty in the estimate.

In simple terms, it’s like a bar plot, but with dots and lines instead of bars.

```plaintext
# Axis-level function
sns.pointplot(data=tips, x="sex", y="total_bill")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851069840/672d040d-9789-472a-8ee8-64d90e20c317.png align="center")

```plaintext
# Figure-level function
sns.catplot(data=tips, x="sex", y="total_bill", hue="smoker", ci=None, kind="point")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851093816/705c9f3e-2170-4a17-962a-a4c6eaced509.png align="center")

#### (iii) Count plot

A Count plot is a special case of a bar plot. Instead of calculating a statistical measure (like mean or median) for a numeric variable, it simply shows the number of observations in each category.

You can think of it as a histogram for categorical data, while histograms work with continuous variables, count plots work with categories.

```plaintext
# Axis-level function
sns.countplot(data=tips, x="sex", hue="day")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851132572/44b43431-3f4c-4cf4-8eaf-73ec8a82d5b0.png align="center")

```plaintext
# Figure-level function
sns.catplot(data=tips, x="sex", hue="smoker", kind="count")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851173112/71e2102c-525d-4a72-8ca1-b41a60709561.png align="center")

***Some tips:***

* If you don't specify any kind, Seaborn uses a ***strip plot*** by default in `sns.catplot()`.
    
* Now, here's a little difference between histplot, barplot, and countplot, since all of them kind of look similar (and honestly, it can get confusing sometimes):
    

***Histplot*** → Works on numerical data and shows the distribution of continuous values divided into bins. It’s best used when you want to see how your data is spread(like age, income, or temperature).

***Barplot*** → Works on both categorical and numerical data (one on x-axis, one on y-axis). It displays a summary statistic (mean by default) for each category, making it great for comparing average values across different categories.

***Countplot*** → Works purely on categorical data and shows the count of observations in each category. It’s best used when you just want to see how many items belong to each group.

---

## 4\. Regression plot

A regression plots help you see how one variable affects another, basically showing the relationship between a dependent and an independent variable.

Both `regplot()` and `lmplot()` draw a scatterplot of two variables (x and y), fit a regression line, and even show a 95% confidence interval around it to indicate how reliable the trend is.

***Axis-level function*** -&gt; `regplot`

***Figure-level function*** -&gt; `lmplot`

### (i) Regplot

The `regplot()` function focuses on drawing a simple regression model between two variables.

***Note:*** The hue parameter is not available in `regplot()` because it’s an axis-level function, and regression plots don’t support hue at this level.

```plaintext
sns.regplot(data=tips, x="total_bill", y="tip")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851337668/530d290b-24c0-4bc6-adb1-6d4447898c4a.png align="center")

### (ii) Lmplot

`lmplot()` is the figure-level version that can handle multiple categories using the "hue" parameter. It provides more flexibility and is great when you want to visualize separate regression lines for different groups.

```plaintext
sns.lmplot(data=tips, x="total_bill", y="tip", hue="sex")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851396178/31548eb9-3743-4397-ad42-1271eceeee65.png align="center")

***scatter*** -&gt; It is used to control the scatter points, setting it to "False" hides the dots and only show the regression line.

```plaintext
sns.lmplot(data=tips, x="total_bill", y="tip", scatter=False)
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851414434/902ce8c0-f504-4cb3-96bf-d946e5701b91.png align="center")

***Some tips:***

* In regression plots, ***lmplot()*** is a figure level function, but unlike other figure level plots, we don't use it inside something like `relplot()`, `displot()` or `catplot()` and definitely not as a "kind" parameter, if you try to call it in that way, it'll throw an error.
    
* We use ***regplot()*** when we want a quick linear fit for a single relationship and ***lmplot()*** when we want to compare trends across categories.
    

---

## 5\. Matrix plot

Matrix plots represent data in a color-encoded grid, where the color of each cell corresponds to its value. They’re great for spotting patterns, correlations, and outliers at a glance.

***Note:*** Matrix plots don’t have any figure-level functions.

***Axis-level function*** -&gt; `heatmap()`, `clustermap()`

### (i) Heatmap

A heatmap displays data as a color-encoded matrix that visualizes the magnitude or intensity of values. For this example, let’s use the Titanic dataset, but feel free to experiment with others:

***pivot\_table*** -&gt; Used to reshape data so that long format datasets are converted into wide format. It also handles duplicate values using an aggregate function (mean by default, but you can use sum, max, len, etc.)

```plaintext
df = titanic.pivot_table(index="sex", columns="class", aggfunc="sum", values="survived")
sns.heatmap(df)
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851466062/f9a305bb-e1f4-4823-85b0-07120e3fc647.png align="center")

***annot*** -&gt; Displays the numeric values inside each cell.

***linewidth*** -&gt; Creates small gaps between the grid cells for better readability.

***cmap*** -&gt; Changes the color theme(e.g. "jet", "summer", "winter", "YlGnBu", etc).

```plaintext
sns.heatmap(df, annot=True, linewidth=0.5, cmap="summer")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851516047/2308c219-1415-4389-b673-676ce131c59f.png align="center")

### (ii) Clustermap

A clustermap is like a heatmap, but smarter. It performs hierarchical clustering on both rows and columns to group similar data points together, making it super helpful for uncovering hidden patterns and relationships in complex datasets.

```plaintext
flights_pivot = flights.pivot("month", "year", "passengers")
sns.clustermap(flights_pivot, cmap="YlGnBu")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851596950/f3864af7-bc1b-4abe-9cfb-d65f397341eb.png align="center")

***Some tips:***

* The main difference between ***heatmap()*** and ***clustermap()*** is that:
    
    * ***Heatmap()*** simply shows data values with colors.
        
    * ***Clustermap()*** goes a step further and groups similar rows and columns together using clustering algorithms.
        

So if you just want to visualize values, go with heatmap and if you want to find patterns or relationships, try clustermap.

---

## 6\. Multiplot/ Multi-grid plot

Multiplots allow us to visualize the same type of plot across different subsets of a dataset, making it easy to compare trends, spot patterns, and understand relationships between variables.

### (i) Plotting FacetGrid Vs Facetplot

**Facetplot**

A facetplot is basically a collection of multiple subplots of the same kind, where each subplot displays a subset of data. These plots share the same axes, helping you compare across different categories or conditions.

There’s no standalone “facetplot” function, it’s created when you combine multiple subplots of other Seaborn plots.

```plaintext
sns.relplot(data=tips, x="total_bill", y="tip", col="smoker", row="time", kind="scatter")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851716720/8d98aec6-ae8a-4b72-996e-c07e8d4fd163.png align="center")

**FacetGrid**

`FacetGrid` is a class in Seaborn that helps you build facet plots in a more structured way. It allows you to map specific plots to a grid of subplots and control how data subsets are visualized.

```plaintext
g = sns.FacetGrid(tips, col="smoker", row="time", hue="sex")
g.map(sns.scatterplot, "total_bill", "tip")
g.add_legend()
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851738923/0e082b23-8a3b-4d75-aa98-901415789153.png align="center")

### (ii) Plotting Pairwise Relationship (PairGrid Vs Pairplot)

Pairwise relationships automatically detect all numerical columns in a dataset and create pairs, so that every numeric variable is plotted against every other one. These plots help in understanding how different variables relate to each other.

**PairGrid**

`PairGrid` is a lower-level, more customizable class. It creates a grid of subplots where each one represents the relationship between two variables(or the distribution of one variable on the diagonal).

```plaintext
g1 = sns.PairGrid(data=iris, hue="species")
g1.map(sns.scatterplot)
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851784251/c7181ac8-96a8-4a0b-bc45-1f9730025518.png align="center")

You can even customize what appears by:

* ***map\_diag*** -&gt; For diagonal elements
    
* ***map\_upper*** -&gt; For upper-triangle plots
    
* ***map\_lower*** -&gt; For lower-triangle plots
    
* ***map\_offdiag*** -&gt; For all off-diagonal plots (both upper & lower)
    

```plaintext
g3 = sns.PairGrid(data=iris, hue="species")
g3.map_diag(sns.boxplot)
g3.map_upper(sns.kdeplot)
g3.map_lower(sns.pointplot)
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851816403/1dea73e2-bdf4-4f8e-ae57-3f5148880cec.png align="center")

**Pairplot**

`Pairplot` is a high-level and simpler version of PairGrid. It automatically creates a grid of scatterplots for all numerical pairs and adds histograms or KDE plots on the diagonals. It’s great when you want quick, standard pairwise visualizations.

```plaintext
sns.pairplot(iris)
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851966286/19467635-4421-4f9a-9a63-7b676d807304.png align="center")

```plaintext
sns.pairplot(iris, hue="species")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760851986267/0631457b-80a8-4ce9-be17-4cbcae4ab6ee.png align="center")

### (iii) JointGrid Vs Jointplot

**JointGrid**

`JointGrid` is a flexible class that underlies Seaborn’s `jointplot()`. It creates a grid with a central plot for the joint distribution and smaller plots on top and right for marginal (univariate) distributions.

You can customize what type of plot appears in each section:

```plaintext
g = sns.JointGrid(data=tips, x="total_bill", y="tip")
g.plot(sns.kdeplot, sns.violinplot)
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760852045739/b4ccf5cd-2c27-4bca-9b3f-696e2562f8f0.png align="center")

**Jointplot**

`Jointplot` acts as a high-level, convenient wrapper around the `JointGrid`. It automatically creates joint plots(like scatter, regression, KDE, or hexbin) with optional marginal plots. It’s perfect for quick joint visualizations without worrying about layout or configuration The default kind in `jointplot()` is "scatter".

```plaintext
sns.jointplot(data=tips, x="total_bill", y="tip", kind="hist", hue="sex")
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1760852086712/c1377984-35c4-45df-b6ee-72943e3348ef.png align="center")

---

### Bonus Tip

To save any figure generated from your plots, simply use:

```plaintext
plt.savefig("figure_name.png")
```

---

So yes, if you’ve made it this far, then congratulations, you now know Seaborn! Hope it was of some help to you.

Thankyou for checking this blog out!
