Report with plots and tables

Python code

"""PDF report generation from a Pug template embedding code to generate
plots and tables.

A HTML page is generated from a template and rendered as a local PDF file.
"""

import pandas
import matplotlib.pyplot as plt
from pdf_reports import pug_to_html, write_report

dataframe = pandas.DataFrame.from_records({
    "Name": ["Anna", "Bob", "Claire", "Denis"],
    "Age": [12,22,33,44],
    "Height (cm)": [140, 175, 173, 185]
}, columns=["Name", "Age", "Height (cm)"])

html = pug_to_html("with_plots_and_tables.pug", dataframe=dataframe)
write_report(html, "with_plots_and_tables.pdf")

Pug template

h1 Example document with plot and table

#sidebar: p I am an example PDF generated with PDF Reports

h3 Our Data

{{ pdf_tools.dataframe_to_html(dataframe) }}


h3 Age versus height

center
  - var figure = dataframe.plot("Age", "Height (cm)")
  img(src="{{ pdf_tools.figure_data(figure, (6, 4)) }}")


<style> h3 {margin-top: 4em;} </style>

Result

PDF link