Data Visualization with Matplotlib & Seaborn

Learn how to visually explore and communicate data insights using Matplotlib and Seaborn in Python.

1️⃣ What is Data Visualization?

Learn More

Data Visualization is the graphical representation of data to identify patterns, trends, and outliers.

Real-life example:

A business uses charts to understand monthly sales growth and customer behavior.

2️⃣ Why Data Visualization Matters

3️⃣ Matplotlib Overview

Matplotlib is the core plotting library in Python. It gives complete control over every element of a plot.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [10, 20, 25, 30]

plt.plot(x, y)
plt.xlabel("X Axis")
plt.ylabel("Y Axis")
plt.title("Simple Line Plot")
plt.show()
      

4️⃣ Seaborn Overview

Seaborn is built on top of Matplotlib and provides high-level, beautiful statistical visualizations.

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme()
data = [10, 20, 25, 30]

sns.lineplot(x=[1,2,3,4], y=data)
plt.show()
      

5️⃣ Common Types of Plots

Plot Type Use Case
Line PlotTrends over time
Bar ChartCategory comparison
HistogramDistribution of data
Scatter PlotRelationship between variables
Box PlotOutliers and spread

6️⃣ Pandas Integration

import pandas as pd

df = pd.DataFrame({
  "Year": [2020, 2021, 2022],
  "Sales": [200, 300, 450]
})

df.plot(x="Year", y="Sales", kind="bar")
plt.show()
      

7️⃣ Customization & Styling

plt.figure(figsize=(8,5))
plt.plot(x, y, color="green", marker="o")
plt.grid(True)
plt.show()
      

8️⃣ Typical Data Visualization Workflow

  1. Load data
  2. Clean data
  3. Choose plot type
  4. Customize visualization
  5. Interpret insights

9️⃣ Real-World Use Cases

🔗 External References