Data Analyst

Module 6 of 12

Module 6: Data Visualization

5 min read883 words
What you'll learn
Create publication-quality plots with MatplotlibBuild statistical visualizations with SeabornDesign interactive charts and dashboards with PlotlyChoose the right chart type for your data and audienceApply design principles that make visualizations clear and compelling

"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?

QuestionChart typeTypical library
Distribution?Histogram, box, violinSeaborn
Compare categories?Bar, grouped barMatplotlib / Seaborn
Trend over time?Line, areaMatplotlib / Plotly
Two numeric variables?Scatter, heatmapSeaborn
Parts of a whole?Stacked bar, treemapPlotly / Matplotlib
Many variables at once?Pair plot, parallel coordsSeaborn / 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 typeUse for
SequentialOrdered magnitude
DivergingAbove/below a midpoint
CategoricalDistinct groups (≤7–8)

Check contrast for color-vision accessibility; don’t rely on color alone.

PitfallSafer habit
Rainbow for categoriesDistinct hues + patterns/labels
Red/green only for bad/goodAdd 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.

python
[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, not figure_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

  1. Matplotlib for control; Seaborn for stats; Plotly for interaction.
  2. Match chart type to the question, not to what looks fancy.
  3. Declutter: fewer colors, clearer labels, one main idea per view.
  4. Label axes with units; legends should earn their space.

Resources for Further Learning

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.