October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Save a Matplotlib Table as a PDF in Python

Add the table to an Axes, then save its containing Figure as a PDF. Use tight bounds for content that risks clipping, or PdfPages to create a multi-page file.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Save the Figure that contains the table—not the table artist itself. Add the table to an Axes with ax.table(...), then export the Figure with fig.savefig("table.pdf", format="pdf").

Save one Matplotlib table as a PDF

A Matplotlib table is drawn as part of a Figure. The standard export path is therefore to create the Figure and Axes, add the table to the Axes, and call savefig on the Figure. Matplotlib documents PDF as a supported output format in its Figure.savefig API and backend guide.

import matplotlib.pyplot as plt

headers = ["Name", "Score"]
rows = [["Ari", 92], ["Bea", 87]]

fig, ax = plt.subplots()
ax.axis("off")  # Hide axes so the output focuses on the table.
ax.table(cellText=rows, colLabels=headers, loc="center")
fig.savefig("table.pdf", format="pdf", bbox_inches="tight")

Replace headers and rows with your own column labels and data. The .pdf extension makes the output filename clear; format="pdf" explicitly selects PDF output.

Choose the page bounds and size

bbox_inches="tight" asks Matplotlib to fit the saved bounds around the Figure’s visible artists, which can help keep table labels or cells from being clipped. You can tune the whitespace around that tight bounding box with pad_inches; the documented default is 0.1 inches. See the savefig parameters.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the PDF must use a predictable page size or consistent margins, set the Figure dimensions when creating it, for example with fig, ax = plt.subplots(figsize=(8, 4)). A tight bounding box can change the saved extent to fit content, so inspect the exported PDF when fixed page geometry matters. To preserve the canvas dimensions, omit bbox_inches="tight" and adjust the figure size or table layout instead.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Put multiple figures in one PDF

For a PDF with several pages, use Matplotlib’s PdfPages context manager and save each Figure as a page. The official PDF backend guide documents this approach.

import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages

with PdfPages("tables.pdf") as pdf:
    for headers, rows in datasets:
        fig, ax = plt.subplots()
        ax.axis("off")
        ax.table(cellText=rows, colLabels=headers, loc="center")
        pdf.savefig(fig)
        plt.close(fig)

Here, datasets should be an iterable of (headers, rows) pairs. Each call to pdf.savefig(fig) adds that Figure as a page; closing it after saving helps release resources in longer loops.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.