Python for Data Science & Automation · Module 4: Exploratory Data Analysis (EDA) & Visualization · Lesson 17 of 34

4.2 Statistical Data Visualization with Seaborn

4.2 Statistical Data Visualization with Seaborn

Seaborn is a Python data visualization library built on top of Matplotlib. It provides a high-level interface for creating attractive and statistically informative visualizations.

While Matplotlib gives detailed control over individual plot elements, Seaborn makes many statistical visualizations easier to create with less code.

In this lesson, you will learn:
  • What Seaborn is and why it is used
  • Installing and importing Seaborn
  • Using Seaborn with pandas DataFrames
  • Understanding long-form and wide-form data
  • Distribution visualization
  • Histograms and KDE plots
  • Box plots
  • Violin plots
  • Pair plots
  • Heatmaps
  • Categorical visualizations
  • Count plots
  • Regression plots
  • Grouping and the hue parameter
  • Customizing Seaborn charts
  • Choosing the right statistical visualization
  • Common mistakes and best practices

1. What Is Seaborn?

Seaborn is a Python library designed specifically for statistical data visualization.

It works particularly well with:

  • pandas DataFrames
  • NumPy arrays
  • Statistical datasets
  • Exploratory Data Analysis (EDA)
  • Machine Learning datasets
pandas + Seaborn + Matplotlib → Powerful EDA Workflow

Seaborn provides convenient functions for exploring relationships, distributions, categories, and statistical patterns.

2. Seaborn vs Matplotlib

Matplotlib Seaborn
Lower-level plotting library. Higher-level statistical visualization library.
Provides extensive customization. Provides convenient statistical plotting functions.
Requires more code for some statistical plots. Often requires less code.
Works with many types of data structures. Works especially naturally with pandas DataFrames.
Highly useful for detailed figure control. Highly useful for statistical EDA.
Remember:

Seaborn does not replace Matplotlib. Seaborn is built on top of Matplotlib and can be combined with it.

3. Installing Seaborn

Install Seaborn using pip:

pip install seaborn

With Conda:

conda install seaborn

In a Jupyter Notebook:

%pip install seaborn

4. Importing Seaborn

import seaborn as sns

sns is the conventional alias used for Seaborn.

Matplotlib is commonly imported alongside Seaborn:

import seaborn as sns
import matplotlib.pyplot as plt

5. Your First Seaborn Visualization

import seaborn as sns
import matplotlib.pyplot as plt

data = [12, 15, 18, 20, 22, 25, 28, 30]

sns.histplot(data=data)

plt.show()

Seaborn creates the visualization while Matplotlib can be used to display and further customize the figure.

6. Working with a pandas DataFrame

Seaborn becomes especially powerful when working with pandas DataFrames.

import pandas as pd

df = pd.DataFrame({
    "Hours": [
        2, 3, 4, 5, 6,
        7, 8, 9, 10, 11
    ],

    "Score": [
        48, 52, 58, 64, 69,
        74, 80, 84, 89, 94
    ],

    "Class": [
        "A", "A", "B", "B", "A",
        "B", "A", "B", "A", "B"
    ]
})

print(df)

Once the data is stored in a DataFrame, Seaborn functions can reference columns directly.

7. Long-Form Data

Seaborn works particularly well with long-form data, where each observation is represented by a row and variables are stored in columns.

Student Subject Score
Student 1 Science 82
Student 2 Science 76
Student 1 Mathematics 88
Student 2 Mathematics 79

This structure makes it easy for Seaborn to map variables to visual properties.

8. The hue Parameter

One of Seaborn's most useful features is the hue parameter.

It allows observations to be visually separated according to a categorical variable.

sns.scatterplot(
    data=df,
    x="Hours",
    y="Score",
    hue="Class"
)

plt.show()

Here, the Class column determines the visual grouping of observations.

Memory Tip:

hue = "Which category should be visually distinguished?"

9. Distribution Visualization

Distribution visualizations help us understand how numerical observations are spread across their possible values.

They can help identify:

  • Central tendency
  • Spread
  • Skewness
  • Clusters
  • Potential outliers
  • General shape of the data

10. Histograms with Seaborn

Use sns.histplot() to create a histogram.

scores = [
    45, 52, 56, 61, 64,
    67, 70, 72, 75, 78,
    81, 84, 87, 90, 94,
    98
]

sns.histplot(
    data=scores
)

plt.title("Score Distribution")
plt.xlabel("Score")
plt.ylabel("Frequency")

plt.show()

11. Controlling Histogram Bins

The bins parameter controls the number or structure of histogram intervals.

sns.histplot(
    data=scores,
    bins=5
)

plt.show()

Choosing an appropriate number of bins is important because too few bins can hide patterns while too many can make a distribution appear unnecessarily noisy.

12. Kernel Density Estimation (KDE)

KDE provides a smooth estimate of the probability density of numerical data.

A KDE curve can help visualize the overall shape of a distribution.

sns.kdeplot(
    data=scores
)

plt.title("Score Density")
plt.xlabel("Score")

plt.show()
Concept:

A histogram shows frequency within bins, while a KDE provides a smooth representation of the distribution's density.

13. Histogram with KDE

Seaborn can display a histogram together with a KDE curve.

sns.histplot(
    data=scores,
    bins=6,
    kde=True
)

plt.title(
    "Score Distribution with Density"
)

plt.xlabel("Score")
plt.ylabel("Frequency")

plt.show()

14. Box Plots

A box plot summarizes the distribution of numerical data using quartiles and can help identify potential outliers.

A standard box plot represents:

  • Median
  • First quartile (Q1)
  • Third quartile (Q3)
  • Interquartile range (IQR)
  • Potential outliers
sns.boxplot(
    data=df,
    y="Score"
)

plt.title("Score Distribution")

plt.show()

15. Understanding the Box Plot

Component Meaning
Median Middle value of the ordered data.
Q1 25th percentile.
Q3 75th percentile.
IQR Q3 − Q1.
Whiskers Show the range according to the box-plot convention.
Points beyond whiskers May indicate potential outliers.
IQR = Q3 − Q1

16. Comparing Distributions with Box Plots

Box plots become particularly useful when comparing numerical distributions across categories.

sns.boxplot(
    data=df,
    x="Class",
    y="Score"
)

plt.title(
    "Score Distribution by Class"
)

plt.show()

This allows you to compare the center, spread, and potential outliers of different groups.

17. Violin Plots

A violin plot combines aspects of a box plot with a density representation.

sns.violinplot(
    data=df,
    x="Class",
    y="Score"
)

plt.title(
    "Score Distribution by Class"
)

plt.show()
When useful:

Violin plots are useful when you want to compare groups while also seeing more information about the shape of their distributions.

18. Count Plots

A count plot displays the number of observations in each category.

sns.countplot(
    data=df,
    x="Class"
)

plt.title(
    "Number of Students by Class"
)

plt.xlabel("Class")
plt.ylabel("Count")

plt.show()

Count plots are useful for examining categorical frequencies.

19. Statistical Bar Plots

Seaborn's barplot() is different from a basic Matplotlib bar chart because it is designed around statistical aggregation.

sns.barplot(
    data=df,
    x="Class",
    y="Score"
)

plt.title(
    "Average Score by Class"
)

plt.show()

The exact estimator and error representation can be controlled through Seaborn's parameters.

Important distinction:

countplot() counts observations, whereas barplot() summarizes a numerical variable across categories.

20. Strip Plots

A strip plot displays individual observations for categorical groups.

sns.stripplot(
    data=df,
    x="Class",
    y="Score"
)

plt.title(
    "Individual Scores by Class"
)

plt.show()

Strip plots are useful when the individual observations themselves are important.

21. Swarm Plots

A swarm plot arranges individual observations so that overlapping points are easier to distinguish.

sns.swarmplot(
    data=df,
    x="Class",
    y="Score"
)

plt.title(
    "Individual Scores by Class"
)

plt.show()
Use carefully:

Swarm plots can become crowded when a dataset contains a very large number of observations.

22. Pair Plots

A pair plot provides a matrix of pairwise relationships between numerical variables in a dataset.

It is particularly useful during EDA when you want to quickly inspect relationships across several variables.

import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset("iris")

sns.pairplot(
    df
)

plt.show()

23. Pair Plot with Categories

A categorical variable can be supplied using hue.

sns.pairplot(
    df,
    hue="species"
)

plt.show()

This helps identify whether different groups occupy different regions of the feature space.

Pair Plot Structure:
  • Off-diagonal plots → relationships between variables
  • Diagonal plots → distribution of individual variables

24. When Should You Use a Pair Plot?

Pair plots are useful when:

  • The dataset contains several numerical features.
  • You are performing initial EDA.
  • You want to inspect possible correlations.
  • You want to identify clusters.
  • You want to compare distributions by category.
Limitation:

Pair plots can become difficult to read when the dataset contains many numerical variables.

25. Correlation and Heatmaps

A correlation matrix summarizes pairwise relationships between numerical variables.

Pandas can calculate the correlation matrix:

correlation = df.corr(
    numeric_only=True
)

print(correlation)

The resulting matrix can be visualized with a Seaborn heatmap.

26. Heatmaps

A heatmap represents numerical values using visual intensity, making patterns in a matrix easier to identify.

correlation = df.corr(
    numeric_only=True
)

sns.heatmap(
    correlation
)

plt.title(
    "Correlation Matrix"
)

plt.show()

27. Displaying Values in a Heatmap

Use annot=True to display numerical values inside the heatmap cells.

sns.heatmap(
    correlation,
    annot=True
)

plt.title(
    "Correlation Matrix"
)

plt.show()
Tip:

Annotations are particularly useful for small or medium-sized matrices where the individual values need to be read.

28. Formatting Heatmap Values

The fmt parameter can control how annotated values are displayed.

sns.heatmap(
    correlation,
    annot=True,
    fmt=".2f"
)

plt.show()

Here, values are displayed with two decimal places.

29. Square Heatmaps

For correlation matrices, square cells can make the matrix easier to inspect.

sns.heatmap(
    correlation,
    annot=True,
    fmt=".2f",
    square=True
)

plt.show()

30. Regression Visualization

Seaborn can visualize a relationship between two numerical variables together with a fitted regression model.

sns.regplot(
    data=df,
    x="Hours",
    y="Score"
)

plt.title(
    "Study Hours vs Score"
)

plt.show()

Regression visualization is useful when investigating whether a relationship between variables can be approximated by a statistical model.

31. Relationship Plots with relplot()

sns.relplot() provides a figure-level interface for relational plots.

sns.relplot(
    data=df,
    x="Hours",
    y="Score",
    hue="Class"
)

plt.show()

Relational plots are useful for examining how numerical variables relate to each other.

32. Seaborn Themes and Styles

Seaborn provides built-in styling options that can change the overall appearance of plots.

sns.set_theme()

sns.histplot(
    data=scores
)

plt.show()

You can also select a theme explicitly.

sns.set_theme(
    style="whitegrid"
)

Common styles include:

  • darkgrid
  • whitegrid
  • dark
  • white
  • ticks

33. Color Palettes

Seaborn provides color palettes designed for categorical and numerical data.

sns.set_palette(
    "deep"
)

A palette can also be supplied to an individual plot:

sns.boxplot(
    data=df,
    x="Class",
    y="Score",
    palette="Set2"
)
Visualization Principle:

Use color to communicate information, not merely for decoration. Make sure categorical groups remain distinguishable and the chart remains readable.

34. Faceting with col and row

Seaborn figure-level functions can create separate panels for different categories.

sns.relplot(
    data=df,
    x="Hours",
    y="Score",
    col="Class"
)

plt.show()

Faceting is useful when a single visualization becomes crowded and separate panels make group comparisons clearer.

35. Categorical Visualization with catplot()

catplot() provides a figure-level interface for categorical plots.

sns.catplot(
    data=df,
    x="Class",
    y="Score",
    kind="box"
)

plt.show()

The kind parameter determines the type of categorical visualization.

36. Common Categorical Plot Types

Kind Purpose
strip Display individual observations.
swarm Display individual observations with reduced overlap.
box Compare distributions using box plots.
violin Compare distributions and density shapes.
bar Compare statistical estimates across categories.
count Display category frequencies.

37. Comparing Distributions by Category

A useful EDA technique is to compare the distribution of a numerical variable across categories.

sns.histplot(
    data=df,
    x="Score",
    hue="Class",
    kde=True
)

plt.title(
    "Score Distribution by Class"
)

plt.show()

This can reveal whether different groups have different distributions.

38. KDE by Category

sns.kdeplot(
    data=df,
    x="Score",
    hue="Class",
    fill=True
)

plt.title(
    "Score Density by Class"
)

plt.show()

This allows the density shapes of multiple categories to be compared.

39. Visualizing Discrete Numerical Values

Some numerical variables represent counts or other discrete values. Seaborn provides parameters that can help communicate this structure appropriately.

sns.histplot(
    data=df,
    x="Score",
    discrete=True
)

plt.show()

40. Data Preparation Before Seaborn

Visualization should generally be performed after checking the quality of the data.

print(df.info())
print(df.isnull().sum())
print(df.describe())

If necessary, handle missing or invalid values before plotting.

clean_df = df.dropna()

sns.boxplot(
    data=clean_df,
    x="Class",
    y="Score"
)

plt.show()
Important:

Do not automatically delete missing observations simply to make a chart work. First determine why the values are missing and whether removing them is analytically appropriate.

41. Complete EDA Example Using the Iris Dataset

Seaborn includes several example datasets that are useful for learning visualization techniques.

import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset(
    "iris"
)

print(df.head())

print(df.describe())

The Iris dataset contains measurements such as sepal and petal dimensions along with the species category.

42. Iris Distribution Visualization

sns.histplot(
    data=df,
    x="petal_length",
    hue="species",
    kde=True
)

plt.title(
    "Petal Length Distribution by Species"
)

plt.show()

43. Iris Box Plot

sns.boxplot(
    data=df,
    x="species",
    y="petal_length"
)

plt.title(
    "Petal Length by Species"
)

plt.show()

44. Iris Pair Plot

sns.pairplot(
    df,
    hue="species"
)

plt.show()

This is a powerful example of how several numerical relationships can be explored simultaneously.

45. Iris Correlation Heatmap

correlation = df.corr(
    numeric_only=True
)

sns.heatmap(
    correlation,
    annot=True,
    fmt=".2f",
    square=True
)

plt.title(
    "Feature Correlation"
)

plt.show()

46. Controlling Figure Size

Seaborn works with Matplotlib's Figure system, so Matplotlib functions can be used to control the figure.

plt.figure(
    figsize=(10, 6)
)

sns.boxplot(
    data=df,
    x="species",
    y="petal_length"
)

plt.tight_layout()
plt.show()

Figure-level Seaborn functions such as pairplot(), relplot(), and catplot() have their own sizing parameters and return Seaborn objects that can be further configured.

47. Saving Seaborn Visualizations

Since Seaborn uses Matplotlib, standard Matplotlib saving functionality can be used.

sns.histplot(
    data=df,
    x="petal_length"
)

plt.title(
    "Petal Length Distribution"
)

plt.savefig(
    "petal_distribution.png",
    dpi=300,
    bbox_inches="tight"
)

plt.show()
Tip:

Higher resolution and appropriate bounding-box settings are useful when preparing figures for reports, presentations, or publications.

48. Axes-Level vs Figure-Level Functions

Seaborn functions can broadly be understood as either axes-level or figure-level.

Type Examples Typical Use
Axes-level scatterplot(), histplot(), boxplot() Draw on a particular Axes.
Figure-level relplot(), catplot(), displot(), pairplot() Manage a complete figure and potentially multiple facets.
Exam Point:

Knowing whether a Seaborn function is axes-level or figure-level helps when combining plots and controlling their layout.

49. Important Distribution Functions

Function Purpose
sns.histplot() Histogram and distribution visualization.
sns.kdeplot() Kernel density estimation.
sns.ecdfplot() Empirical cumulative distribution visualization.
sns.displot() Figure-level distribution visualization.

50. Important Relational Functions

Function Purpose
sns.scatterplot() Show relationships between numerical variables.
sns.lineplot() Show trends and relationships across an ordered variable.
sns.regplot() Show a relationship with a fitted regression model.
sns.relplot() Figure-level relational visualization.

51. Important Categorical Functions

Function Purpose
sns.countplot() Count observations in categories.
sns.barplot() Compare statistical estimates across categories.
sns.boxplot() Compare distributions using quartiles.
sns.violinplot() Compare distributions and density shapes.
sns.stripplot() Show individual observations.
sns.swarmplot() Show individual observations with reduced overlap.
sns.catplot() Figure-level categorical visualization.

52. Matrix and Relationship Visualization

Function Purpose
sns.heatmap() Visualize matrix values.
sns.pairplot() Explore pairwise relationships and distributions.

53. Choosing the Right Seaborn Visualization

Analytical Question Recommended Visualization
How is a numerical variable distributed? Histogram / KDE
Are there potential outliers? Box plot
How do distributions differ between groups? Box plot / Violin plot / KDE
How are categories distributed? Count plot
How do two numerical variables relate? Scatter plot
Is there a possible linear relationship? Regression plot
How do many numerical variables relate? Pair plot
How are correlations distributed across variables? Heatmap
Easy Memory Trick:
  • Distribution → Histogram / KDE
  • Spread & Outliers → Box Plot
  • Shape + Distribution → Violin Plot
  • Many Relationships → Pair Plot
  • Matrix / Correlation → Heatmap
  • Category Counts → Count Plot
  • Relationship → Scatter Plot
  • Trend + Model → Regression Plot

54. Seaborn EDA Workflow

A practical EDA workflow can follow this sequence:

  1. Load the dataset.
  2. Inspect its structure.
  3. Check data types.
  4. Check missing values.
  5. Calculate descriptive statistics.
  6. Examine distributions.
  7. Compare categories.
  8. Explore relationships.
  9. Inspect correlations.
  10. Investigate potential outliers.
  11. Form hypotheses for further analysis.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.read_csv(
    "students.csv"
)

print(df.info())
print(df.describe())
print(df.isnull().sum())

sns.histplot(
    data=df,
    x="Score",
    kde=True
)

plt.show()

sns.boxplot(
    data=df,
    x="Class",
    y="Score"
)

plt.show()

sns.pairplot(
    df,
    hue="Class"
)

plt.show()

55. Seaborn Best Practices

  1. Understand the dataset before visualizing it.
  2. Select a chart according to the analytical question.
  3. Use meaningful titles and axis labels.
  4. Use hue when categorical grouping improves interpretation.
  5. Avoid unnecessary colors and decorations.
  6. Do not use too many categories in a single visualization.
  7. Check whether outliers are genuine observations or data quality issues.
  8. Be careful when interpreting correlation as causation.
  9. Use pair plots selectively because they can become crowded.
  10. Ensure that the visualization communicates the actual structure of the data honestly.

56. Common Seaborn Mistakes

  1. Using the wrong visualization: A count plot and box plot answer different questions.
  2. Ignoring missing values: Missing observations can affect the interpretation.
  3. Using too many variables in a pair plot: The resulting matrix may become unreadable.
  4. Misinterpreting outliers: A potential outlier is not automatically an error.
  5. Confusing correlation with causation: A statistical association does not prove that one variable causes another.
  6. Using excessive colors: Color should communicate categories or another meaningful dimension.
  7. Ignoring categorical data types: Appropriate categorical variables can make grouping and visualization substantially clearer.

57. Seaborn Interview Questions

Q1. What is Seaborn?

View Answer

Seaborn is a Python statistical data visualization library built on top of Matplotlib. It provides a high-level interface for creating informative statistical graphics.

Q2. How is Seaborn related to Matplotlib?

View Answer

Seaborn is built on top of Matplotlib and can use Matplotlib functionality for further customization and figure control.

Q3. What is the conventional alias for Seaborn?

View Answer
import seaborn as sns

Q4. What is the purpose of hue?

View Answer

hue maps a categorical variable to a visual grouping, allowing observations from different categories to be distinguished.

Q5. What is the difference between countplot() and barplot()?

View Answer

A count plot displays the number of observations in each category, while a bar plot displays a statistical estimate of a numerical variable for each category.

Q6. What is a pair plot?

View Answer

A pair plot displays pairwise relationships among numerical variables along with individual variable distributions.

Q7. What is a heatmap?

View Answer

A heatmap represents matrix values through visual intensity and is commonly used to display correlation matrices.

Q8. What information does a box plot provide?

View Answer

A box plot summarizes the distribution of numerical data using quartiles, median, interquartile range, whiskers, and potential outliers.

Q9. What is KDE?

View Answer

Kernel Density Estimation is a non-parametric method for estimating and visualizing the probability density of numerical data.

Q10. What is the difference between axes-level and figure-level Seaborn functions?

View Answer

Axes-level functions draw onto a particular Matplotlib Axes, whereas figure-level functions manage an entire figure and can provide features such as faceting.

58. Examination Questions — MCQs

Q1. Seaborn is primarily used for:

  1. Database management
  2. Statistical data visualization
  3. Operating system development
  4. Web server configuration

Answer: B — Statistical data visualization

Q2. What is the conventional alias for Seaborn?

  1. sb
  2. sea
  3. sns
  4. sn

Answer: C — sns

Q3. Which function creates a box plot?

  1. sns.boxplot()
  2. sns.boxgraph()
  3. sns.distribution()
  4. sns.quartile()

Answer: A — sns.boxplot()

Q4. Which function is commonly used to create a pair plot?

  1. sns.pairs()
  2. sns.pairplot()
  3. sns.pairgraph()
  4. sns.relationships()

Answer: B — sns.pairplot()

Q5. Which Seaborn function is used for heatmaps?

  1. sns.matrix()
  2. sns.heatmap()
  3. sns.correlation()
  4. sns.heat()

Answer: B — sns.heatmap()

Q6. Which parameter is commonly used to distinguish categories in Seaborn?

  1. group
  2. category
  3. hue
  4. colorby

Answer: C — hue

Q7. Which function displays category frequencies?

  1. sns.countplot()
  2. sns.frequency()
  3. sns.categoryplot()
  4. sns.frequencyplot()

Answer: A — sns.countplot()

Q8. Which parameter displays values inside a heatmap?

  1. values=True
  2. numbers=True
  3. annot=True
  4. show=True

Answer: C — annot=True

59. Practical Examination Questions

Question 1 — Distribution

Create a Seaborn histogram with a KDE curve for a list of examination scores.

import seaborn as sns
import matplotlib.pyplot as plt

scores = [
    45, 52, 58, 61,
    65, 68, 72, 75,
    78, 81, 84, 88,
    91, 95
]

sns.histplot(
    data=scores,
    bins=6,
    kde=True
)

plt.title(
    "Examination Score Distribution"
)

plt.xlabel("Score")
plt.ylabel("Frequency")

plt.show()

Question 2 — Box Plot

Compare examination scores across two classes using a box plot.

sns.boxplot(
    data=df,
    x="Class",
    y="Score"
)

plt.title(
    "Score Distribution by Class"
)

plt.show()

Question 3 — Pair Plot

Create a pair plot and distinguish observations according to a categorical variable.

sns.pairplot(
    df,
    hue="Class"
)

plt.show()

Question 4 — Correlation Heatmap

Calculate a correlation matrix and visualize it using a heatmap.

correlation = df.corr(
    numeric_only=True
)

sns.heatmap(
    correlation,
    annot=True,
    fmt=".2f"
)

plt.title(
    "Correlation Matrix"
)

plt.show()

Question 5 — Category Counts

Display the number of observations in each class using a count plot.

sns.countplot(
    data=df,
    x="Class"
)

plt.title(
    "Number of Students by Class"
)

plt.show()

60. Scenario-Based Questions

Scenario 1: You want to determine whether examination scores contain unusually high or low observations.

Recommended visualization: Box plot.

Scenario 2: You want to compare the distribution of scores for several classes.

Recommended visualization: Box plot, violin plot, or KDE by category.

Scenario 3: You have five numerical features and want an initial overview of their pairwise relationships.

Recommended visualization: Pair plot.

Scenario 4: You have calculated correlations among numerical features and want to identify strong positive and negative relationships quickly.

Recommended visualization: Correlation heatmap.

Scenario 5: You want to know how many observations belong to each category.

Recommended visualization: Count plot.

61. Quick-Fire Interview Revision

Question Quick Answer
Seaborn alias? sns
Seaborn built on? Matplotlib
Distribution? histplot() / kdeplot()
Box plot? boxplot()
Violin plot? violinplot()
Pairwise relationships? pairplot()
Correlation matrix? heatmap()
Category frequency? countplot()
Category grouping? hue
Regression visualization? regplot()

62. Seaborn Quick Revision Cheatsheet

Command Purpose
import seaborn as sns Import Seaborn.
sns.set_theme() Set Seaborn theme.
sns.histplot() Create histogram.
sns.kdeplot() Create KDE distribution.
sns.displot() Figure-level distribution plot.
sns.boxplot() Create box plot.
sns.violinplot() Create violin plot.
sns.stripplot() Display individual observations.
sns.swarmplot() Display individual observations with reduced overlap.
sns.countplot() Count categorical observations.
sns.barplot() Compare statistical estimates.
sns.scatterplot() Show relationships between variables.
sns.lineplot() Show trends.
sns.regplot() Show regression relationship.
sns.relplot() Figure-level relational visualization.
sns.pairplot() Explore pairwise relationships.
sns.heatmap() Visualize matrix values.
sns.catplot() Figure-level categorical visualization.
hue= Group observations by category.
annot=True Display heatmap values.
fmt=".2f" Format annotated numerical values.

63. Key Takeaways

  • Seaborn is a high-level statistical visualization library built on Matplotlib.
  • It integrates naturally with pandas DataFrames.
  • histplot() and kdeplot() help analyze distributions.
  • boxplot() helps analyze spread, quartiles, and potential outliers.
  • violinplot() combines distribution shape with categorical comparison.
  • pairplot() provides a broad view of pairwise relationships.
  • heatmap() is particularly useful for correlation matrices and other numerical matrices.
  • countplot() is useful for categorical frequencies.
  • hue is one of the most important Seaborn parameters for grouping observations.
  • Good visualization begins with understanding the data and the analytical question.
Remember:

Distribution → Histogram / KDE   |   Outliers → Box Plot   |   Relationships → Pair Plot   |   Correlation → Heatmap   |   Categories → Count / Box / Violin