To make a report from Python code, write a .qmd file that mixes Markdown text with {python} code chunks and run quarto render report.qmd. Quarto runs the chunks, puts the charts, tables and inline numbers into the text, and writes HTML, PDF or Word. It is the report counterpart of a notebook: you rerun one command when the data changes. For a PDF built from Matplotlib figures alone, see How to Generate PDF Data Reports.
This post used Quarto 1.11 with Matplotlib 3.11 and pandas 3.1. Install it with brew install --cask quarto (or pip install quarto-cli), plus pip install jupyter so Quarto can run Python. The parameters section also needs pip install papermill, and the table below uses tabulate.
Quick Example
Save this as report.qmd. The data is simulated: monthly checkouts at three library branches, seeded so you get the same numbers.
---
title: "Library Checkouts, 2026"
subtitle: "Monthly branch report"
author: "Data team"
date: 2026-12-06
format:
html:
embed-resources: true
toc: true
typst: default
jupyter: python3
execute:
echo: false
---
```{python}
#| tags: [parameters]
branch = "Central"
```
```{python}
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from IPython.display import Markdown
rng = np.random.default_rng(21)
months = pd.date_range("2026-01-01", periods=12, freq="MS")
base = {"Central": 5200, "Eastside": 3100, "Riverside": 2400}
season = 1 + 0.22 * np.sin((months.month - 4) / 12 * 2 * np.pi)
df = pd.DataFrame({
name: (level * season * rng.normal(1, 0.04, 12)).round().astype(int)
for name, level in base.items()
}, index=months)
mine = df[branch]
total = f"{mine.sum():,}"
peak = f"{mine.idxmax():%B}"
share = f"{mine.sum() / df.sum().sum():.0%}"
```
## Summary
The **`{python} branch`** branch lent **`{python} total`** items in 2026,
`{python} share` of all checkouts across the system. Its busiest month was
`{python} peak`. @fig-monthly shows the full year and @tbl-quarters breaks it
into quarters.
```{python}
#| label: fig-monthly
#| fig-cap: "Monthly checkouts, with the other two branches in gray."
fig, ax = plt.subplots(figsize=(6.5, 3.3), layout="constrained")
for name in df.columns.drop(branch):
ax.plot(df.index, df[name], color="#c9ced6", lw=1.5)
ax.plot(df.index, mine, color="#0b6e6e", lw=2.5, marker="o")
ax.set_ylabel("Items checked out")
ax.xaxis.set_major_formatter(mdates.DateFormatter("%b"))
ax.xaxis.set_major_locator(mdates.MonthLocator())
ax.spines[["top", "right"]].set_visible(False)
plt.show()
```
## By quarter
```{python}
#| label: tbl-quarters
#| tbl-cap: "Checkouts by quarter."
quarters = mine.groupby(mine.index.quarter).sum()
table = pd.DataFrame({
"Quarter": [f"Q{q}" for q in quarters.index],
"Checkouts": [f"{v:,}" for v in quarters],
"Change": ["-"] + [f"{c:+.0%}" for c in quarters.pct_change().dropna()],
})
Markdown(table.to_markdown(index=False))
```
::: {.callout-note}
This report was built with `quarto render`. Change the `branch` parameter
to build the same report for another branch.
:::
quarto render report.qmd

One command wrote report.html (a single file, because of embed-resources: true) and report.pdf, since both formats are listed under format:. Pass --to html or --to typst to build only one. The report is for the Central branch, which lent 62,389 items in 2026, 48% of the system total. Its busiest month was July.
What goes in a .qmd file?
A .qmd file has three parts:
- A YAML header between two
---lines with the title, author, date, output formats and options. - Markdown text with headings, lists, links and tables, as in any Markdown file.
- Code chunks fenced with
```{python}. Quarto runs them top to bottom in one Python session, so a variable from an early chunk is available in later ones.
Options for a chunk go in #| comment lines at the top of it. The ones used above:
| Option | What it does |
|---|---|
echo: false (in the header under execute:) |
Hide the code, show only the output. Set it to true for a tutorial. |
label: fig-monthly |
Names the chunk. A fig- or tbl- prefix makes it a numbered figure or table you can cite as @fig-monthly. |
fig-cap / tbl-cap |
The caption under the figure or table. |
tags: [parameters] |
Marks the chunk that holds default parameter values (see below). |
How do I put a Matplotlib chart in a Quarto report?
Draw it in a chunk and call plt.show() at the end. Quarto saves the figure and places it with the caption from fig-cap. The report body is narrow, so a figsize around (6.5, 3.3) fills it, and a wider figure gets scaled down with its text. Any plotting library that draws in Jupyter works the same way, including Plotly and Altair in the HTML output.
In the Quick Example, the other two branches are drawn first with color="#c9ced6" and the branch being reported is drawn last with color="#0b6e6e", lw=2.5, marker="o". Gray for context and one color for the subject keeps a figure readable when it is shrunk to a page.
How do I show a Python value inside the text?
Write {python} name in backticks inside a paragraph. Quarto evaluates the expression and pastes the result into the sentence (inline expressions need Quarto 1.4 or later). Compute the formatted string in a chunk first, as the Quick Example does with total, peak and share, so the number in the text always comes from the same data as the chart:
The **`{python} branch`** branch lent **`{python} total`** items in 2026.
Nothing is typed by hand, so a report that gets rebuilt next month cannot disagree with its own chart.
How do I make a PDF?
Quarto's typst format writes a PDF with no other software to install, which is the quickest route. The pdf format goes through LaTeX instead and needs a TeX distribution (quarto install tinytex sets one up).

The same chunks, figure, table and cross-references produced this page. Quarto picks the right output for each format, so the table is an HTML table in the browser and a typeset table in the PDF. To add Word, put docx: default under format:.
How do I make one report for each group?
Add a chunk tagged parameters with default values, then override them on the command line with -P name:value. The branch = "Central" chunk in the Quick Example is the one doing this. Use -o to give each output its own file name:
for b in Central Eastside Riverside; do
quarto render report.qmd --to typst -P branch:$b -o report-$b.pdf
done

Running this made three PDFs. The text, the highlighted line and the quarterly table changed for each branch while the layout stayed the same. Parameters need the papermill package installed, and Quarto reports "The papermill package is required for processing --execute-params" if it is missing.
Quarto vs Jupyter nbconvert vs PdfPages
| Quarto | jupyter nbconvert |
Matplotlib PdfPages |
|
|---|---|---|---|
| Source file | .qmd (plain text) or .ipynb |
.ipynb |
A Python script |
| Output | HTML, PDF, Word, slides, websites | HTML, PDF, Markdown | PDF of figures only |
| Text around the charts | Markdown with cross-references | Notebook Markdown cells | None, unless you draw it |
| Hide the code | One option, echo: false |
Extra flags or a template | Not applicable |
| One report per group | -P name:value |
Via papermill | A loop in Python |
| Extra install | Quarto | None beyond Jupyter | None |
Use Quarto when the report has prose, tables and several charts and you want one source for HTML and PDF. Use PdfPages when the deliverable is only a stack of figures.
Practical Tips
- Commit the
.qmdfile, not the output. It is plain text, so a diff shows what changed in the report. - Set a fixed
date:when you need the same file every build.date: todaychanges the output each day. - A chunk that fails stops the render and Quarto prints the traceback. Add
#| error: trueto keep going and show the error in the report while you debug. - Slow chunks can be cached with
execute: cache: truein the header, so a rebuild after a text edit does not rerun the data load. - Use
quarto preview report.qmdwhile writing. It rebuilds and reloads the browser each time you save. - Data with real names in it (customers, patients) belongs in the report only if the people reading it should see it, since the HTML embeds everything.