Skip to content
Tutorials Center
My learning

Topics

Lesson 45 of 57 ยท Projects

Project: Sales Dashboard

Build a one-page sales dashboard in Matplotlib with subplot_mosaic: a KPI strip, a trend line, a regional bar chart, a share donut and annotations.

In this project you will build the kind of one-page dashboard that people actually ask analysts for: a row of headline numbers, a trend over time, a comparison between regions and a breakdown of shares, all in one consistent style. You will use almost everything from the tutorial: subplot_mosaic, annotations, bar charts, pie and donut charts, styles and the habits from Reproducible and Automated Charts.

There are no files to download. The data is synthetic and created with a fixed random seed, so your dashboard matches the one described here exactly. The project has four steps: generate and summarize the data, design the layout, fill each panel, and polish with annotations and a reusable function.

What we are building

KPI strip Revenue, orders and growth at a glance.
Trend Monthly revenue with the peak marked.
Regions Bars sorted by total sales.
Share Product mix as a donut.

One figure, four panels, one style.

1 / 2

Step 1: the data and the numbers

Dashboards start with numbers, not pictures. Decide which questions the page must answer: how much did we sell, is it growing, where, and what mix? Then compute those answers in a table before drawing anything. That keeps the drawing code simple and lets you check figures by eye.

The data below holds one row per month, region and product, for 2025. Revenue has a gentle upward trend, a seasonal bump in summer, and some noise, plus a different base level for each region and product.

Python Step 1: synthetic data and KPIs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Read the printed numbers carefully: about 3.22 million in revenue, 18,054 orders, growth of 44% from January to December, August as the best month and East as the leading region. They are the story the dashboard has to tell, and they are what you compare against when you check the charts. The monthly series, the sorted region totals and the product shares are the three tables the panels will draw from. Notice sort_values() on the regions: for a bar chart, sorting before plotting is almost always right (see Bar Charts).

Step 2: design the layout

Think of a dashboard as a grid. The KPI strip goes on top, wide and short. The trend gets the most space because it is the main story. Regions and product share sit side by side underneath. With subplot_mosaic you describe that picture in text, and every panel gets a name you can use as a dictionary key:

TEXT
KKKK
TTTT
TTTT
RRSS

Here K is the KPI strip, T the trend, R the regions bar chart and S the share donut. A letter repeated across a row or column makes the panel span those cells. Use height_ratios to make the KPI strip thin and the trend tall, and layout="constrained" so labels never collide.

Before you fill the panels, set the style once. A short rc_context dictionary (a light grid, no top and right spines, left-aligned bold titles) is enough to make every chart look related. Choose one accent color and a muted gray for everything else, so the eye goes to what matters.

Step 3: fill each panel

Give every panel its own small function that takes an Axes and data. That mirrors the advice for reusable chart functions: panels can be tested, reused and rearranged without touching one another. The KPI panel is a trick worth knowing: it is an empty axes with the frame hidden, and text placed in axes coordinates (transform=ax.transAxes).

Python Step 2 and 3: the dashboard, panel by panel

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You should see a thin strip of four big numbers across the top, a tall blue trend area in the middle that climbs to a peak in August, and the two smaller panels underneath. A few details are worth noticing, because they separate a dashboard that is easy to read from one that is cluttered:

  • One accent color. The leading region is blue and the others are gray, so the bar chart answers "who leads?" before anyone reads a label.
  • Direct labels. bar_label prints values at the ends of the bars, so the x axis needs no gridlines to read from.
  • Honest axes. Both bar-style charts start at zero. The trend panel uses set_ylim(0, ...) so the growth is shown at its true size.
  • A donut instead of a pie. With three categories and percentages printed in the ring, it is readable, but a bar of three shares would also be fine; see the lesson on pie and donut charts for the trade-offs.

Step 4: annotate and package

A chart becomes a message when you point at the interesting part. The peak month deserves a callout, and the KPI strip is more useful with a hint of context. Add the annotation to the trend panel with ax.annotate, using xytext offset in points and an arrow, as in Annotations and Arrows.

Finally, wrap everything in one function, build_dashboard(sales), that returns the figure. The function does not call plt.show(), so you can save it as a PNG for e-mail or a PDF for print, or call it once per quarter with a different slice of the data. The next TryIt performs the last step: it runs on the sales table, adds the callout and a footer, and prints the file size of the saved PNG.

Python Step 4: annotations and a reusable function

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The peak callout tells the reader exactly where to look, and because build_dashboard only needs a DataFrame in the same shape, you can reuse it for another year, another product line or a single region.

Ideas to extend it

  • Add a second line to the trend panel for last year's revenue (dashed gray) so growth is visible against a baseline.
  • Replace the donut by a stacked bar of products per region, using bottom= as in the bar chart lesson.
  • Add a quarter argument to build_dashboard that filters the data, then loop over the four quarters and save one PNG each, closing every figure.
  • Turn the KPI numbers into small "sparkline" panels, each with a tiny line of its monthly history.
  • Draw a small caption under each panel that states the takeaway in words.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In the layout string "KKKK;TTTT;TTTT;RRSS", how many grid cells does the trend panel T cover?

    T appears in two rows with four columns each, so the panel spans 2 x 4 = 8 cells.
  2. 2. How is the KPI strip drawn?

    set_axis_off hides the frame and ticks, and ax.text with transform=ax.transAxes places large numbers and labels by fractions of the panel.
  3. 3. Why does build_dashboard return the figure instead of calling plt.show()?

    Returning the figure keeps the function reusable: you can show it, save it as PNG or PDF, or run it in a batch.
  4. 4. Why does the bar chart highlight only the leading region?

    Using a muted color for context and an accent for the key bar lets the reader see the answer before reading any labels.

Summary

  • Start a dashboard with the questions it must answer, and compute those numbers in tables before drawing.
  • subplot_mosaic turns a text layout into named panels; height_ratios and layout="constrained" give a tidy result.
  • Write one small function per panel that takes an Axes and data; a KPI strip is just text on a hidden axes.
  • One accent color, direct labels and zero-based bars make the page readable at a glance.
  • Annotate the interesting point, and wrap everything in a function that returns the figure so it can be reused, saved and tested.

Next, try a second project with seasonal data: Project: Weather Station Report.