Course Overview All Courses Blog Reserve Bootcamp Seat
Data Analysis · Day 4 of 5 ~70 minutes

Visualization — Matplotlib Charts That Tell Stories

Build charts that communicate the answer before anyone reads a word. The chart is the analysis, not the decoration.

Day 1
Day 2
Day 3
4
Day 4
5
Day 5
What You'll Build Today

A chart library for your analysis: a horizontal bar chart for comparisons, a line chart for trends, and a heatmap for region-by-product breakdowns. You'll save each as a PNG file ready to drop into any report or slide deck.

1
Pick the Right Chart

Chart type determines whether people understand you

The single biggest charting mistake analysts make is using the wrong chart type for the question. Here's the decision guide:

Bar Chart

Comparing values across categories. "Which region has highest revenue?" Use horizontal bars when category labels are long.

Line Chart

Showing change over time. "How has revenue trended over 12 months?" Never use bars for time series.

Heatmap

Two-dimensional comparisons. "Which region × product combination is strongest?" Color encodes magnitude instantly.

Scatter Plot

Relationships between two numeric variables. "Is there a correlation between deal size and units?"

Install matplotlib:

bash
pip install matplotlib seaborn
2
Bar Charts

Compare categories cleanly

pythonbar_chart.py
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("sales.csv")
by_region = df.groupby("region")["revenue"].sum().sort_values()

# Create figure
fig, ax = plt.subplots(figsize=(10, 5))

# Horizontal bar chart (better for category labels)
bars = ax.barh(
    by_region.index,
    by_region.values,
    color="#1e3a5f",
    height=0.6
)

# Add value labels on bars
for bar, val in zip(bars, by_region.values):
    ax.text(val + 500, bar.get_y() + bar.get_height()/2,
            f"${val:,.0f}", va="center", fontsize=11)

# Clean up the chart
ax.set_title("Revenue by Region", fontsize=16, fontweight="bold", pad=16)
ax.set_xlabel("Total Revenue ($)")
ax.spines["top"].set_visible(False)
ax.spines["right"].set_visible(False)
plt.tight_layout()
plt.savefig("revenue_by_region.png", dpi=150, bbox_inches="tight")
print("Saved revenue_by_region.png")
3
Heatmaps

Show two-dimensional patterns at a glance

pythonheatmap.py
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

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

# Create pivot table: regions as rows, products as columns
pivot = df.pivot_table(
    values="revenue",
    index="region",
    columns="product",
    aggfunc="sum",
    fill_value=0
)

fig, ax = plt.subplots(figsize=(10, 5))

sns.heatmap(
    pivot,
    annot=True,
    fmt=",",
    cmap="Blues",
    ax=ax,
    linewidths=0.5,
    cbar_kws={"label": "Revenue ($)"}
)

ax.set_title("Revenue by Region and Product", fontsize=15, fontweight="bold", pad=14)
plt.tight_layout()
plt.savefig("heatmap.png", dpi=150, bbox_inches="tight")
print("Saved heatmap.png")

Always save to PNG with dpi=150 or higher. 72 DPI looks blurry in slides. 150 is crisp everywhere — presentations, Slack, Word docs.

Day 4 Complete

  • Chose the right chart type for the right question
  • Built a horizontal bar chart with value labels
  • Created a heatmap showing region-by-product revenue
  • Saved charts as high-res PNGs for reports and slides
Day 4 Done

Final Day: Automated Reporting Pipeline

Day 5 wires everything together — pandas, Claude, and matplotlib — into a single script that generates a full HTML report from any CSV.

Go to Day 5
Finished this lesson?