"The purpose of visualization is insight, not pictures." — Ben Shneiderman
Learning Objectives
By the end of this module, you will be able to:
- Create publication-quality plots with Matplotlib
- Build statistical visualizations with Seaborn
- Design interactive charts and dashboards with Plotly
- Choose the right chart type for your data and audience
- Apply design principles that make visualizations clear and compelling
Choosing the Right Chart
Before code, ask: what decision or belief should this chart change?
| Question | Chart type | Typical library |
|---|---|---|
| Distribution? | Histogram, box, violin | Seaborn |
| Compare categories? | Bar, grouped bar | Matplotlib / Seaborn |
| Trend over time? | Line, area | Matplotlib / Plotly |
| Two numeric variables? | Scatter, heatmap | Seaborn |
| Parts of a whole? | Stacked bar, treemap | Plotly / Matplotlib |
| Many variables at once? | Pair plot, parallel coords | Seaborn / Plotly |
Concept: The chart is not the analysis — it’s the argument’s slide deck.
1. Matplotlib — The Foundation
Matplotlib is verbose but total control: figures, axes, subplots, annotations, export to PNG/PDF.
Basic Plots
plt.subplots() returns figure + axes; plot lines with ax.plot, labels with set_xlabel / set_title. Good defaults: limit chartjunk, one story per axes when possible.
Bar Charts
Vertical or horizontal bars for magnitude comparison. Grouped bars for two series side by side; stacked bars for composition (read carefully — area distorts perception).
Subplots — Multiple Charts in One Figure
subplots(nrows, ncols) builds a grid — dashboard-style static layouts. Share axes when scales must align.
Try This! One line chart with a horizontal reference line (target) and a single annotation on the max point.
2. Seaborn — Statistical Visualization
Seaborn sits on Matplotlib with nicer defaults and statistical plot types tied to DataFrames.
Distribution Plots
histplot + KDE, boxplot / violinplot for category vs numeric — see spread and skew at a glance.
Relationship Plots
scatterplot, regplot for trend lines; hue and style encode extra dimensions.
Heatmap — Correlation Matrix
heatmap on df[numeric].corr() — quick multicollinearity sniff test (not causality!).
Pair Plot — Explore All Relationships
Grid of scatterplots for numeric columns — exploratory, not presentation.
Statistical Plots
countplot, barplot with error bars — group summaries with uncertainty cues.
Fun Fact: catplot / relplot add facets (row, col) — small multiples without manual subplot math.
3. Plotly — Interactive Visualization
Plotly = zoom, pan, hover, filters — great for dashboards and HTML sharing. plotly.express mirrors Seaborn’s grammar for common charts.
Basic Plotly Charts
Line, scatter, bar from tidy DataFrames; sunburst / treemap for hierarchy.
Dashboard-Style Layout
make_subplots combines chart types in a grid; consistent template and height for polish.
Animated Charts
animation_frame steps through time — powerful when motion encodes time (don’t overuse in static reports).
4. Design Principles
The Data-Ink Ratio
Maximize ink that encodes data; minimize borders, 3D, gradients that don’t carry information. Highlight one message — dim the rest.
Color Guidelines
| Palette type | Use for |
|---|---|
| Sequential | Ordered magnitude |
| Diverging | Above/below a midpoint |
| Categorical | Distinct groups (≤7–8) |
Check contrast for color-vision accessibility; don’t rely on color alone.
| Pitfall | Safer habit |
|---|---|
| Rainbow for categories | Distinct hues + patterns/labels |
| Red/green only for bad/good | Add icons or text labels |
| 3D bars “for drama” | 2D bar or slope chart |
Fun Fact: Edward Tufte’s “chartjunk” rant aged well — busy backgrounds still hide signal in 2026 decks.
Key Example: One Matplotlib figure: line trend + labeled axes + target line — the minimum viable “professional” chart.
[object Object], matplotlib.pyplot ,[object Object], plt
months = [,[object Object],, ,[object Object],, ,[object Object],, ,[object Object],, ,[object Object],, ,[object Object],]
revenue = [,[object Object],, ,[object Object],, ,[object Object],, ,[object Object],, ,[object Object],, ,[object Object],]
fig, ax = plt.subplots(figsize=(,[object Object],, ,[object Object],))
ax.plot(months, revenue, marker=,[object Object],, color=,[object Object],, linewidth=,[object Object],)
ax.axhline(,[object Object],, color=,[object Object],, linestyle=,[object Object],, alpha=,[object Object],, label=,[object Object],)
ax.set_title(,[object Object],)
ax.set_ylabel(,[object Object],)
ax.legend()
plt.tight_layout()Checklist before you export a chart
- Title states the insight, not just the variable name
- Axes have units (currency, %, count)
- Legend entries are human-readable
- Color is redundant with labels where possible (accessibility)
- No misleading axis truncation for magnitudes (bar charts start at zero)
- Source / time window noted in caption or subtitle
- File name matches content (
revenue_q3_north.png, notfigure_1.png)
Storyboarding: Sketch the slide on paper with one sentence per chart. If you need two sentences, you might need two charts or a simpler message.
Practice Exercises
Exercise 1: Sales Report Visuals (Beginner)
2×2 subplot: line, bar, histogram, pie or treemap by region.
Exercise 2: Distribution Analysis (Intermediate)
Seaborn: violin by department, scatter + reg line, heatmap of averages.
Exercise 3: Interactive Dashboard (Intermediate)
Plotly: four linked views telling one compensation story.
Exercise 4: Before/After Redesign (Advanced)
Ugly chart → clean chart; bullet list of design decisions.
Exercise 5: Small Multiples (Advanced)
Faceted trends by region and product.
Mini-Project: Executive Dashboard
Static + interactive versions: KPIs, trend vs target, top products, segment mix, short captions per chart, consistent palette.
Key Takeaways
- Matplotlib for control; Seaborn for stats; Plotly for interaction.
- Match chart type to the question, not to what looks fancy.
- Declutter: fewer colors, clearer labels, one main idea per view.
- Label axes with units; legends should earn their space.
Resources for Further Learning
- Matplotlib Gallery
- Seaborn Gallery
- Plotly Express Documentation
- From Data to Viz
- Fundamentals of Data Visualization — Claus Wilke
- Storytelling with Data
Key Takeaway
- Pick the chart from the question, not from habit or aesthetics alone.
- Layer libraries: Matplotlib for control, Seaborn for stats, Plotly for exploration.
- Reduce ink that doesn’t encode data; highlight the one claim you need.
- Encode thoughtfully with color (sequential vs categorical) and test accessibility.
- Caption charts so they stand alone in a deck or report.
Next up: Module 7 — Statistics for Data Analysis — the mathematical foundation that makes your visualizations meaningful.