Python Central HubSign in

Data Analytics with Python / Phase 5: Data Visualization with Matplotlib

Matplotlib Mini Project (EDA charts pack)

Build a small “EDA charts pack” using Matplotlib - distribution, category comparison, trend, and relationship.

Goal

Create a reusable set of plots you can apply to any dataset:

  • Histogram (distribution)
  • Bar chart (category counts)
  • Line plot (trend)
  • Scatter plot (relationship)

This mirrors how McKinney approaches exploratory data analysis (EDA) in the book: before modelling anything, look at the shape of your data (histogram), how categories compare (bar chart), how things move over time (line plot), and whether two variables relate (scatter plot). Four charts, four different questions.

diagram An EDA charts pack mermaid
Four standard questions about a dataset, each answered by one chart type.

Sample dataset

Python
import pandas as pd
 
# Small example you can replace with any CSV
df = pd.DataFrame({
    "date": pd.date_range("2025-01-01", periods=10, freq="D"),
    "orders": [120, 140, 130, 160, 155, 170, 180, 175, 190, 200],
    "city": ["Pune", "Delhi", "Pune", "Delhi", "Pune", "Mumbai", "Pune", "Delhi", "Mumbai", "Pune"],
    "amount": [100, 140, 110, 160, 130, 90, 180, 150, 120, 200],
})

1) Histogram

Python
import matplotlib.pyplot as plt
 
plt.figure(figsize=(7, 4))
plt.hist(df["amount"], bins=8, edgecolor="black")
plt.title("Amount distribution")
plt.xlabel("Amount")
plt.ylabel("Count")
plt.tight_layout()
plt.show()

2) Bar chart (counts)

Python
import matplotlib.pyplot as plt
 
counts = df["city"].value_counts()
 
plt.figure(figsize=(7, 4))
plt.bar(counts.index, counts.values)
plt.title("Orders count by city")
plt.xlabel("City")
plt.ylabel("Count")
plt.tight_layout()
plt.show()

3) Line plot (trend)

Python
import matplotlib.pyplot as plt
 
plt.figure(figsize=(7, 4))
plt.plot(df["date"], df["orders"], marker="o")
plt.title("Orders trend")
plt.xlabel("Date")
plt.ylabel("Orders")
plt.xticks(rotation=20)
plt.tight_layout()
plt.show()

4) Scatter plot

Python
import matplotlib.pyplot as plt
 
plt.figure(figsize=(7, 4))
plt.scatter(df["orders"], df["amount"], alpha=0.7)
plt.title("Orders vs amount")
plt.xlabel("Orders")
plt.ylabel("Amount")
plt.tight_layout()
plt.show()

Deliverable

Save some plots with plt.savefig(...) and reuse this structure for your datasets.

Check your understanding

quizCheck yourself
  1. Which four charts make up the EDA pack, and which question does each answer?

    Show answer

    A — Histogram for shape, bar for categories, line for time, scatter for relationships — Four charts answer four questions: the shape of the data, how categories compare, how things move over time, and whether two variables relate.

  2. In the sample data, what does df["city"].value_counts() show for Pune, Delhi and Mumbai?

    Show answer

    A — Pune 5, Delhi 3, Mumbai 2 — Of the 10 rows, Pune appears 5 times, Delhi 3 times and Mumbai twice.

  3. Which call draws the Orders vs amount chart?

    Show answer

    A — plt.scatter(df["orders"], df["amount"], alpha=0.7) — Scatter plots pair two numeric columns point by point, and alpha=0.7 makes overlapping points slightly transparent.

  4. Why does the trend chart use plt.xticks(rotation=20)?

    Show answer

    A — To keep the date labels from overlapping — Long date labels crowd the x-axis, so rotating them makes them readable.

Next

You've completed the Matplotlib phase — continue to the next phase to bring these charts together with pandas' own .plot() shortcuts.

🧪 Try It Yourself

Exercise 1 – Distribution of a column

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 2 – Counts by category

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Exercise 3 – Trend and relationship together

exerciseYour turn

Tab indents. Press Escape, then Tab, to leave the editor. Control plus Enter runs the code; Control plus Shift plus Enter submits it.

Output
Press Run to see what your code prints.

Was this page helpful?

Let us know how we did