Data Science

Data Visualization

Visualization Principles

Module 3 already used matplotlib and seaborn functions as EDA tools. Before going deeper into the libraries themselves (Chapters 2-4), it's worth pausing on why

JrCodex·7 min read

Jr Codex Data Science Notes

Level: Intermediate Prerequisites: Module 3: Exploratory Data Analysis Time to complete: ~20 minutes


Table of Contents

  1. Why Principles Before Tools
  2. Choosing the Right Chart Type
  3. The Data-Ink Ratio
  4. Color: Purposeful, Not Decorative
  5. Common Chart Mistakes
  6. Know Your Audience
  7. Summary & Next Steps

1. Why Principles Before Tools

Module 3 already used matplotlib and seaborn functions as EDA tools. Before going deeper into the libraries themselves (Chapters 2-4), it's worth pausing on why a chart works or fails — the same line of code can produce a genuinely useful visualization or a misleading, cluttered one, depending on the choices behind it.

A Chart Should Answer One Question
─────────────────────────────────────────
  Bad chart:  "here's a lot of data, figure it out"
  Good chart:  "here's the ONE pattern I want you to notice,
                made as obvious as possible"
─────────────────────────────────────────

2. Choosing the Right Chart Type

The type of chart should follow directly from what kind of question you're answering — the same distinction from Module 3's bivariate analysis chapter, now applied to picking a visualization.

Chart Selection Guide
─────────────────────────────────────────
  ONE numeric variable's distribution     → Histogram, box plot
  Comparing a numeric value ACROSS         → Bar chart (for aggregates),
    categories                                grouped box plot (for distributions)
  Relationship between TWO numeric           → Scatter plot
    variables
  Change over TIME                            → Line chart
  Parts of a WHOLE                              → Stacked bar chart
                                                    (pie charts are usually a WORSE choice — Section 5)
  Relationships among MANY numeric               → Correlation heatmap, pair plot (Ch.3)
    variables at once
─────────────────────────────────────────
import matplotlib.pyplot as plt
import pandas as pd
 
df = pd.DataFrame({
    "month": ["Jan", "Feb", "Mar", "Apr", "May"],
    "revenue": [45000, 52000, 48000, 61000, 58000],
})
 
# Change over time → line chart (NOT a bar chart, which implies unrelated categories)
plt.plot(df["month"], df["revenue"], marker="o")
plt.title("Monthly Revenue")
plt.ylabel("Revenue ($)")

A common beginner mistake: using a bar chart for time-series data. Bars visually imply independent, unrelated categories; a line implies continuity and trend — using the wrong one can make a clear upward trend harder to perceive at a glance.


3. The Data-Ink Ratio

A concept from Edward Tufte's classic visualization work: maximize the proportion of "ink" (or pixels) on a chart that actually conveys data, and minimize everything else — gridlines, borders, decorative elements, redundant labels.

import matplotlib.pyplot as plt
 
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
 
# Cluttered version — heavy gridlines, 3D-style shadow effects, unnecessary border
axes[0].bar(["A", "B", "C"], [30, 45, 25], color="gray", edgecolor="black", linewidth=2)
axes[0].grid(True, which="both", linestyle="-", linewidth=1.5)
axes[0].set_title("Cluttered — low data-ink ratio")
 
# Clean version — minimal gridlines, no unnecessary border, direct labels
axes[1].bar(["A", "B", "C"], [30, 45, 25], color="steelblue")
axes[1].spines["top"].set_visible(False)
axes[1].spines["right"].set_visible(False)
axes[1].grid(axis="y", alpha=0.3)
axes[1].set_title("Clean — high data-ink ratio")
Data-Ink Ratio Principle
─────────────────────────────────────────
  Every line, color, and label should EARN its place by
  helping the viewer understand the data faster.
  If removing an element doesn't hurt understanding, remove it.
─────────────────────────────────────────

4. Color: Purposeful, Not Decorative

Color should encode information, not just look nice — three distinct purposes color typically serves in a chart:

Three Legitimate Uses of Color
─────────────────────────────────────────
  1. Categorical distinction   → different colors for different, unordered
                                   groups (e.g. each region a different color)
  2. Sequential/ordered scale     → a single color, varying in INTENSITY,
                                     for an ordered numeric range (e.g. light
                                     to dark blue for low to high values)
  3. Highlighting                   → one color for "the thing to notice",
                                       gray/muted for everything else (context)
─────────────────────────────────────────
import matplotlib.pyplot as plt
 
df_regions = {"North": 45, "South": 38, "East": 30, "West": 62}
 
colors = ["lightgray"] * len(df_regions)
colors[list(df_regions.keys()).index("West")] = "steelblue"      # highlight ONE bar of interest
 
plt.bar(df_regions.keys(), df_regions.values(), color=colors)
plt.title("West Region Stands Out — highlighting in action")

Avoid rainbow/default color cycling when the categories have no inherent order — and never use a red-green gradient alone for anything a colorblind viewer (roughly 8% of men) needs to distinguish; a blue-orange or blue-red scale is a safer default.


5. Common Chart Mistakes

Mistake 1: Truncated Y-Axis (exaggerates differences)
─────────────────────────────────────────
  Y-axis starting at 90 instead of 0 makes a
  91 vs 93 difference look dramatic, when it's actually tiny.
  → For bar charts especially, the y-axis should almost always start at 0.
─────────────────────────────────────────

Mistake 2: Pie Charts with Too Many Slices
─────────────────────────────────────────
  Humans are bad at comparing angles/areas precisely.
  A pie chart with 8+ slices is nearly unreadable.
  → A sorted bar chart almost always communicates the same
    information more clearly.
─────────────────────────────────────────

Mistake 3: 3D Effects on 2D Data
─────────────────────────────────────────
  3D bar/pie charts distort perceived size due to perspective —
  purely decorative, and actively misleading.
  → Never use 3D effects for data that isn't inherently 3-dimensional.
─────────────────────────────────────────

Mistake 4: Too Many Variables in One Chart
─────────────────────────────────────────
  Cramming color + size + shape + position all into one scatter
  plot can overwhelm rather than clarify.
  → Consider faceting (Module 3, Ch.3) into several simpler
    charts instead of one overloaded one.
─────────────────────────────────────────
import matplotlib.pyplot as plt
 
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
 
values = [91, 93, 89, 95]
labels = ["Q1", "Q2", "Q3", "Q4"]
 
# Misleading — truncated y-axis exaggerates small differences
axes[0].bar(labels, values, color="steelblue")
axes[0].set_ylim(85, 96)
axes[0].set_title("Misleading: truncated y-axis")
 
# Honest — starts at 0, differences shown at their true proportional scale
axes[1].bar(labels, values, color="steelblue")
axes[1].set_ylim(0, 100)
axes[1].set_title("Honest: y-axis starts at 0")

6. Know Your Audience

The same underlying data can call for different charts, depending on who's looking at it:

Audience-Driven Chart Choices
─────────────────────────────────────────
  Yourself, during EDA (Module 3):
    → fast, rough, many small plots, default styling is fine

  A technical colleague reviewing your analysis:
    → clear labels, but detail (confidence intervals, sample
      sizes, raw distributions) is welcome and expected

  A business stakeholder in a presentation:
    → ONE clear takeaway per chart, minimal jargon, direct
      annotation of the key insight (Module 5 revisits this
      as "storytelling with data")
─────────────────────────────────────────

A chart built for your own EDA exploration is rarely the right chart to put in a stakeholder presentation — the former optimizes for speed, the latter for clarity to someone without your context. Module 5's storytelling chapter covers this transition in depth.


7. Summary & Next Steps

Key Takeaways

  • Choose chart type based on the question being asked (distribution, comparison, relationship, trend, composition) — using a bar chart for time-series data is a common, avoidable mistake.
  • Maximize the data-ink ratio: every visual element should earn its place by aiding understanding, not decoration.
  • Color should encode meaning (categorical, sequential, or highlighting) — never add color purely for visual appeal, and be mindful of colorblind-safe palettes.
  • Watch for common distortions: truncated y-axes, overcrowded pie charts, 3D effects, and cramming too many variables into one plot.
  • The "right" chart depends on the audience — EDA exploration and stakeholder presentation call for very different levels of polish and simplicity.

Concept Check

  1. Why is a line chart usually more appropriate than a bar chart for showing revenue over months?
  2. What's wrong with starting a bar chart's y-axis at 90 instead of 0?
  3. Name the three legitimate purposes color can serve in a chart.

Next Chapter

Chapter 2: Matplotlib Fundamentals


Jr Codex — 1-on-1 Personalized Coaching | Back to Module Index