Adding Tables to Plots
A Matplotlib table renders a grid of values right inside a figure, letting you pair exact numbers with a chart so a dashboard shows both the visual trend and the precise data behind it.
Learn Adding Tables to Plots in our free Matplotlib course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…
Part of the free Matplotlib course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
In this lesson you'll build tables with ax.table() , add row and column labels, style individual cells, and place a table neatly below a chart.
ax.table() turns a list of rows into a grid. Pass cellText — a list where each inner list is one row of strings — plus colLabels for the headers and a loc for placement. Because the table fills the axes, you usually hide the axes themselves with ax.axis('off') .
What you'll see: a clean three-column table of cafe sales — Drink, Cups, and Price — with a bold header row and four data rows, sitting centered in the figure with no axes around it.
Add rowLabels for a header down the left side and tint headers with colColours / rowColours . To restyle one cell, fetch the cell map with table.get_celld() (keyed by (row, col) , where row 0 is the header) and call set_facecolor() on the cell you want to highlight.
The dashboard classic: a chart on top and its data table underneath. Plot the chart, add the table with loc='bottom' , hide the x tick labels so they do not clash with the table headers, and call plt.subplots_adjust(bottom=...) to make room.
What you'll see: a grouped bar chart of revenue versus costs with a tidy two-row table directly underneath showing the exact monthly figures — a compact dashboard that pairs the visual with the numbers.
Replace each ___ to render a simple two-column table.
Cell values have to be strings. ✅ Convert with str(v) or a list comprehension: [[str(v) for v in row] for row in data] .
There is no room below the axes. ✅ Call plt.subplots_adjust(bottom=0.2) (and left= if you use rowLabels).
Every row needs the same number of columns as there are colLabels . ✅ Make all rows the same width.
Build a table of three players' scores and color the header row gold.
Lesson complete — your figures can show the numbers!
You built tables with ax.table, added row and column labels, recolored individual cells, and placed a data table beneath a chart for a dashboard look.
🚀 Up next: Logarithmic & Symlog Scales — reveal patterns across many orders of magnitude.
Practice quiz
Which argument supplies the grid of cell values to ax.table()?
- data=
- values=
- rows=
- cellText=
Answer: cellText=. cellText is a list of rows, each a list of strings, holding the table's cell values.
What type must every value in cellText be?
- A string
- An integer
- A float
- A NumPy array
Answer: A string. Every cell value must be a string; convert numbers with str() or an f-string.
Which argument adds header cells across the top of the table?
- rowLabels
- colLabels
- headers
- topLabels
Answer: colLabels. colLabels are the header cells across the top, one per column.
How do you place a table directly under a chart?
- loc='above'
- loc='center'
- loc='bottom'
- loc='under'
Answer: loc='bottom'. loc='bottom' positions the table beneath the axes.
What does table.get_celld() return?
- A list of column names
- The total cell count
- The figure object
- A dict of cells keyed by (row, col)
Answer: A dict of cells keyed by (row, col). get_celld() returns a dict keyed by (row, col) where row 0 is the header.
In get_celld(), which key is the FIRST data row, first column?
- (1, 0)
- (0, 0)
- (0, 1)
- (2, 1)
Answer: (1, 0). Row 0 is the header, so the first data row starts at (1, 0).
Which argument adds header cells down the LEFT side?
- sideLabels
- rowLabels
- leftLabels
- indexLabels
Answer: rowLabels. rowLabels are the header cells down the left side, one per row.
How do you make the table's rows taller?
- table.height(2)
- table.resize(2)
- table.scale(1, 1.6)
- table.stretch(1.6)
Answer: table.scale(1, 1.6). table.scale(width, height) scales the cells; a height > 1 makes rows taller.
How do you recolor a single cell's background?
- cell.color('red')
- cell.fill('red')
- cell.bg('red')
- cell.set_facecolor('red')
Answer: cell.set_facecolor('red'). Call set_facecolor() on the Cell you fetched from get_celld().
Why call plt.subplots_adjust(bottom=0.2) with a bottom table?
- To make room so the table is not cut off
- To rotate the table
- To delete the chart
- To change the colormap
Answer: To make room so the table is not cut off. It adds space below the axes so the loc='bottom' table fits.