Introduction to Seaborn Python (original) (raw)

Seaborn is a Python library for creating statistical visualizations. It provides clean default styles and color palettes, making plots more attractive and easier to read. Built on top of Matplotlib and integrated with pandas data structures, Seaborn makes data visualization easier and more consistent.

Categories of Plots 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:

Installation

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.

**Note: Most of these dependencies are automatically installed when you install Seaborn, but it is important to have compatible versions to avoid errors.

Basic Plots in Seaborn

1. Lineplot

Lineplot is used to show the relationship between two continuous variables. It is commonly used for time-series or ordered data.

**Example: Visualizing trend over time

Python `

import seaborn as sns import matplotlib.pyplot as plt

fmri = sns.load_dataset("fmri") sns.lineplot(x="timepoint", y="signal", hue="region", data=fmri) plt.show()

`

**Output

Screenshot-2026-04-08-151549

Line graph showing signal changes across timepoints for different regions.

**Explanation: x="timepoint" sets time on x-axis, y="signal" values plotted on y-axis and hue="region" separates lines by region

2. Scatterplot

Scatterplot is used to show the relationship between two numerical variables. It helps in identifying patterns or correlations.

**Example: Relationship between total bill and tip

Python `

import seaborn as sns import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.scatterplot(x="total_bill", y="tip", hue="day", data=tips) plt.show()

`

**Output

Screenshot-2026-04-08-151755

Scatter plot showing how tips vary with total bill across different days.

**Explanation: x, y numerical variables and hue="day" adds color grouping

3. Barplot

Barplot is used to compare numerical values across categories. It shows the average value with confidence intervals.

**Example: Average total bill per day

Python `

import seaborn as sns import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.barplot(x="day", y="total_bill", data=tips) plt.show()

`

**Output

Screenshot-2026-04-08-152027

Bar chart showing average total bill for each day.

**Explanation: x="day" categories and y="total_bill" aggregated values (mean by default)

4. Boxplot

Boxplot is used to show the distribution of data based on quartiles. It helps identify spread and outliers.

**Example: Distribution of total bill by day

Python `

import seaborn as sns import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.boxplot(x="day", y="total_bill", data=tips) plt.show()

`

**Output

Screenshot-2026-04-08-152252

Box plot showing median, quartiles, and outliers for each day.

5. Histplot

Histplot is used to visualize the distribution of a single numerical variable.

**Example: Distribution of total bill

Python `

import seaborn as sns import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")

sns.histplot(tips["total_bill"], kde=True) plt.show()

`

**Output

Screenshot-2026-04-08-152547

Histogram with a smooth density curve.

**Explanation: kde=True adds density curve

6. Heatmap

Heatmap is used to visualize matrix-like data using colors. It is commonly used for correlation matrices.

**Example: Correlation heatmap

Python `

import seaborn as sns import matplotlib.pyplot as plt

tips = sns.load_dataset("tips") corr = tips.corr(numeric_only=True)

sns.heatmap(corr, annot=True, cmap="coolwarm") plt.show()

`

**Output

Screenshot-2026-04-08-152739

Color-coded matrix showing correlations between variables.

**Explanation: annot=True displays values and cmap controls color scheme

7. Pairplot

Pairplot is used to plot pairwise relationships between multiple numerical variables.

**Example: Pairwise relationships in dataset

Python `

import seaborn as sns import matplotlib.pyplot as plt

iris = sns.load_dataset("iris") sns.pairplot(iris, hue="species") plt.show()

`

**Output

Screenshot-2026-04-08-153639

Grid of scatterplots and histograms for all variable pairs.

**Explanation: hue adds category distinction