๐Ÿ‘ฉโ€๐Ÿ’ผ
Your context
Wanjiru โ€” analyst at Jumia Nairobi

Your manager walks over at 9am on Friday: "We need a chart for the CEO deck tomorrow. Six months of daily order volume, with a call-out on Black Friday. Make it look sharp." You have the data (a CSV of 180 days), but you've only ever made basic line charts. You know matplotlib can do better โ€” but the API feels overwhelming. Figure? Axes? Why do I need both? In the next 30 minutes, you'll master the mental model and ship five production-ready charts.

๐Ÿ“ฅ
Sample dataset included
180 days of Jumia Kenya daily orders, revenue, basket size, and top category

Why Matplotlib? The Fig/Ax Model

Matplotlib is powerful because it separates what you're drawing on (the figure) from what you're drawing (the axes). Most one-liners skip this โ€” they create both behind the scenes. But when you need fine-grained control (custom colors, annotations, multiple plots), you must understand the model.

Basic line chart: plain one-liner style (no styling, just raw data).
Simple line chart of Jumia daily orders over 180 days
What this shows: 180 days of daily orders, displayed as a line. No title, no axis labels, no grid โ€” just the raw visual. This is what happens when you call plt.plot(x, y) and plt.show(). It works, but it tells no story and looks unfinished. The CEO would ask: "What is this? What do the axes mean?"

One-liner vs. The Right Way

Compare two approaches:

The one-liner (quick & dirty)
The right way (fig/ax model)
Why the difference matters: The one-liner is fast for exploration, but you have zero control. The fig/ax approach forces you to name the objects, which means you can call methods on them: ax.set_title(), ax.grid(), ax.annotate(). For production work โ€” the kind that lands in a slide deck โ€” always use fig/ax.

Styling Essentials: Title, Labels, Grid, Color

A polished chart has four non-negotiables: a clear title, axis labels, a subtle grid, and brand colors. Let's upgrade the basic line chart with each.

Same data, styled properly: title, labels, grid, brand color, and annotation on the Black Friday spike.
Styled line chart with title, axis labels, grid, and Black Friday annotation
What changed: We added ax.set_title() and ax.set_xlabel() / ax.set_ylabel() to label the axes. Grid lines make it easier to read values. The purple color (#6D28D9) matches Ramayai's brand. The arrow annotation draws attention to the Black Friday spike around day 150 โ€” the moment orders nearly tripled. This is the chart you'd show your manager.
Styling: title, labels, grid, and custom color

Subplots: Multiple Charts in One Figure

Often you need to show related views side-by-side: orders vs. revenue, distribution of basket sizes, scatter of order volume vs. revenue. Use plt.subplots(rows, cols) to create a grid of axes, then populate each.

2x2 subplot grid: line (orders), bar (revenue by category), histogram (basket sizes), scatter (orders vs revenue).
Four-panel subplot showing line, bar, histogram, and scatter charts
What this shows: Panel A: orders trend over time. Panel B: total revenue by category (Electronics leads). Panel C: histogram of average basket size (normally distributed around 2850 KSh). Panel D: strong positive correlation between orders and revenue โ€” more orders = more money, as expected. One figure, four insights. This is what you'd put on a slide to tell a complete story.
Create a 2x2 subplot grid

Horizontal Bar Charts: When Labels Are Long

Vertical bar charts are the default, but when your categories have long names or you want to sort by value, horizontal bars are clearer. Use ax.barh() instead of ax.bar().

Total revenue by category, sorted lowest-to-highest. Horizontal bars make long labels readable.
Horizontal bar chart of revenue by category, sorted
What this shows: Electronics generates the most revenue, followed by Fashion, Groceries, and Home. The horizontal orientation keeps category names from rotating or overlapping. By sorting (Home โ†’ Groceries โ†’ Fashion โ†’ Electronics), the viewer's eye reads top-to-bottom in a natural order. Small detail, big impact on clarity.
Horizontal bar chart, sorted by value

Annotations & Publication Quality: Before You Ship

The difference between "a chart I made in Jupyter" and "a chart ready for the CEO deck" is attention to detail: highlighted regions, statistics boxes, clean typography, and proper spacing.

Publication-ready chart: highlighted Black Friday region, statistics box, and legend. Ready for slides or PDF export.
Publication-quality chart with Black Friday region highlighted and statistics box
What this shows: The chart tells the full story at a glance. Title (clear and bold), legend (says "Black Friday Period"), highlighted region (amber box from days 145โ€“155), and a statistics box in the corner (Regular: 359 orders/day, Black Friday: 928 orders/day, Spike: 2.6x). The grid is subtle, colors are on-brand. This is the chart you show your manager at 5pm Thursday, and by 9am Friday it's in the deck.
Publication-quality chart with annotations

Export for Slides & PDF

Once your chart is publication-ready, export it in two formats:

  • SVG for web/slides: Vector format, scales without quality loss. fig.savefig('chart.svg')
  • PNG (150โ€“300 DPI) for documents: Raster, but high DPI looks crisp in PDFs. fig.savefig('chart.png', dpi=300)
  • PDF for print: Vector + text, perfect for reports. fig.savefig('chart.pdf', dpi=300, bbox_inches='tight')
Export in multiple formats for different uses

Common Pitfalls & How to Avoid Them

1. Forgetting tight_layout()

When you have subplots or a complex layout, labels can overlap. Always call fig.tight_layout() before saving or showing.

2. Using bare plt.* instead of ax methods

Mixing plt.plot() (global) with ax.set_title() (on a specific axes) is confusing. Pick one: either all pyplot (plt.*) for simple exploration, or all object-oriented (fig, ax) for production.

3. Not setting figsize early

Size matters. Mobile slide decks want 10ร—6; printed reports want 8ร—10. Set figsize when you create the figure: fig, ax = plt.subplots(figsize=(10, 6))

4. Ignoring gridlines or making them too heavy

A grid helps readability, but only if it's subtle. Use ax.grid(True, alpha=0.2, linestyle='--') โ€” light and dashed, never solid or opaque.

5. Skipping axis labels

Never assume your audience knows what the axes mean. Every chart needs ax.set_xlabel() and ax.set_ylabel().

1 / 3

Quick check-in

What does the "figure" represent in matplotlib's fig/ax model?
The canvas or window that holds everything (fig is like the paper, ax is what you draw on it)
The same thing as "axes" โ€” just different names
A pre-made chart template from the library
The export format for saving images
Which method adds a title to the chart?
plt.title('My Chart')
ax.set_title('My Chart')
fig.add_title('My Chart')
plt.set_header('My Chart')
When exporting a chart for a PDF report, what DPI do you recommend?
72 DPI (web resolution)
150 DPI (lower file size)
300 DPI (crisp print quality)
As high as possible (1000+ DPI)
Africa & India's Best AI Academy
๐Ÿค– AI-first ๐ŸŽ“ Placement Assistance

Ready to make charts people share?

Join the Best AI Program: The AI-Era Analyst โ€” 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Analyst โ†’