Seaborn Complete Notes
What is Seaborn?
Seaborn is a Python data visualization library built on top of Matplotlib. It helps to:- Create beautiful statistical plots
- Reduce plotting code
- Improve plot styling automatically
- Visualize complex datasets easily
- Data Science
- Machine Learning
- Data Analysis
Installing Seaborn
Installation
Importing Libraries
Explanation
sns→ seaborn aliaspd→ pandasnp→ numpy
Loading Dataset in Seaborn
sns.get_dataset_names()
Shows available built-in datasets.
Output
List of datasets like:sns.load_dataset()
Loads built-in dataset.
Output
Explanation
Loads penguins dataset into DataFrame.value_counts()
Counts category occurrences.
Output
Explanation
Counts penguins species frequency.Scatter Plot
sns.scatterplot()
Used to visualize relationship between two numerical variables.
Explanation
x→ x-axis variabley→ y-axis variablehue→ color grouping
Output
Scatter plot grouped by island colors.
Styling in Seaborn
sns.set_style()
Changes plot background style.
Available Styles
- white
- dark
- whitegrid
- darkgrid
- ticks
sns.despine()
Removes plot borders/spines.
Explanation
Removes left spine.
sns.set_context()
Controls scaling of plot elements.

Context Types
| Context | Usage |
|---|---|
| paper | Small plots |
| notebook | Default |
| talk | Presentation |
| poster | Large displays |
Palette
palette
Controls color theme.
Explanation
Uses Dark2 color palette.
Scatter Plot with Style and Alpha
Explanation
style→ marker style changesalpha→ transparency
Strip Plot
sns.stripplot()
Shows distribution of categorical data.
Output
Categorical scatter-like plot.
dodge=True
Separates hue categories.

jitter=True
Adds random spacing.
Explanation
Avoids overlapping points.
Swarm Plot
sns.swarmplot()
Automatically prevents overlap.
Output
Bee swarm arrangement of points.
Histogram
sns.histplot()
Shows data distribution.
Explanation
multiple='stack'→ stacked histogram
Regression Plot
sns.regplot()
Adds regression trend line.
Explanation
Shows linear relationship between variables.
Line Plot
sns.lineplot()
Shows continuous trends.
Explanation
- Different colors → islands
- Different styles → sex

Joint Plot
sns.jointplot()
Combines scatter plot + distributions.
Output
Central scatter plot with side histograms.
KDE Joint Plot
Explanation
Uses density estimation instead of scatter points.
Bar Plot
sns.barplot()
Shows average values by category.
Explanation
Compares mean body mass.
Count Plot
sns.countplot()
Counts categorical occurrences.
Output
Bar chart of species counts.
Box Plot
sns.boxplot()
Shows:
- median
- quartiles
- outliers
Output
Distribution comparison across species.
Violin Plot
sns.violinplot()
Combines boxplot + density plot.
Explanation
Width shows density of values.
Split Violin Plot
Explanation
Male and female shown in one violin.
Inner Quartiles
Explanation
Shows quartile lines inside violin.
Swarm + Violin Combined
Explanation
Combines density + individual points.
KDE Plot
sns.kdeplot()
Smooth probability density curve.
Explanation
- Smooth histogram alternative
fill=Truefills area
Heatmap
sns.heatmap()
Displays matrix with colors.
Explanation
corr()→ correlation matrixannot=True→ show valuesvmin→ minimum color scale
Output
Correlation heatmap.
Rug Plot
sns.rugplot()
Shows individual data points as ticks.
Output
Small tick marks along axis.
Pair Plot
sns.pairplot()
Creates pairwise plots automatically.
Output
Grid of scatter plots and histograms.
Pair Plot with Histogram
Explanation
Diagonal uses histograms instead of KDE.
Pair Grid
sns.PairGrid()
Custom subplot grid.
Explanation
map_upper()→ upper triangle plotsmap_lower()→ lower triangle plotsmap_diag()→ diagonal plots
Output
Fully customized pairwise visualization grid.
Seaborn Plot Summary
| Plot | Purpose |
|---|---|
| scatterplot | Relationship between variables |
| stripplot | Categorical spread |
| swarmplot | Non-overlapping stripplot |
| histplot | Distribution |
| regplot | Regression trend |
| lineplot | Continuous trends |
| jointplot | Combined distributions |
| barplot | Average comparison |
| countplot | Frequency count |
| boxplot | Outlier detection |
| violinplot | Density + boxplot |
| kdeplot | Smooth distribution |
| heatmap | Correlation matrix |
| rugplot | Individual data ticks |
| pairplot | Automatic pair relationships |
| PairGrid | Custom pairwise plots |
Important Seaborn Functions
| Function | Purpose |
|---|---|
set_style() | Plot style |
set_context() | Scaling |
despine() | Remove borders |
scatterplot() | Scatter plot |
histplot() | Histogram |
regplot() | Regression line |
lineplot() | Line graph |
barplot() | Bar chart |
countplot() | Count categories |
boxplot() | Quartiles & outliers |
violinplot() | Density visualization |
heatmap() | Matrix heatmap |
pairplot() | Pairwise analysis |
Seaborn Helps
Seaborn helps to:- Create attractive statistical plots
- Analyze distributions
- Detect patterns
- Understand correlations
- Visualize categorical and numerical data easily
- Less code
- Better styling
- Easy integration with Pandas
- Built on Matplotlib