TutorialsPythonSeaborn for Statistical Charts

Seaborn for Statistical Charts

Create beautiful distribution, correlation and categorical charts with Seaborn

Seaborn is built on Matplotlib and provides a high-level interface for statistical visualisation. Its charts look better by default and require less code. Data analysts use Seaborn for: distribution plots (histograms, KDE), correlation heatmaps, boxplots for outlier detection, and categorical comparisons.

Example

Essential Seaborn charts for EDA
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd

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

# Set style
sns.set_theme(style="whitegrid", palette="muted")

# HISTOGRAM — distribution of sales
plt.figure(figsize=(8, 5))
sns.histplot(df["Sales"], bins=30, kde=True, color="#c47f00")
plt.title("Distribution of Sales")
plt.show()

# BOXPLOT — outliers and spread by category
plt.figure(figsize=(10, 6))
sns.boxplot(data=df, x="Region", y="Sales", palette="Set2")
plt.title("Sales Distribution by Region")
plt.show()

# HEATMAP — correlation matrix
plt.figure(figsize=(8, 6))
numeric_df = df.select_dtypes(include="number")
corr = numeric_df.corr()
sns.heatmap(corr, annot=True, fmt=".2f", cmap="coolwarm",
            center=0, square=True)
plt.title("Correlation Matrix")
plt.show()

# BARPLOT — mean with confidence interval
sns.barplot(data=df, x="Region", y="Sales", estimator="mean",
            palette="Blues_d")
💡 sns.heatmap(corr, annot=True) is the fastest way to spot correlations across all numeric columns at once — a standard EDA step.

Key Points

  • import seaborn as sns — universal convention
  • sns.set_theme() sets a consistent style — call once at the top of your notebook
  • Seaborn plots accept a DataFrame directly: sns.boxplot(data=df, x="col", y="col")
  • sns.heatmap(df.corr(), annot=True) shows correlations across all numeric columns
  • Seaborn returns a Matplotlib Axes — you can use plt.title() etc. after any Seaborn call

Practice Question

Which Seaborn chart is best for identifying outliers in a numeric column across different categories?

Related Topics

Matplotlib BasicsCreate line charts, bar charts and scatter plots with Python's core plotting libraryExploratory Data Analysis (EDA) WorkflowA systematic 6-step EDA process every data analyst should follow on any new datasetCorrelation AnalysisFind relationships between variables using Pearson correlation and Seaborn heatmapsOutlier Detection in PythonIdentify and handle outliers using IQR, z-score and visualisation methods