One interesting solution is to use plotly because it can generate good charts, and it can also write formulas with latex. Used with a HTML library like xhtml2pdf, you can generate any report.
In addition to that, it is a python library, so you can collect data from anywhere (database, excel file, etc.)
To install it:
pip install plotly
pip install xhtml2pdf
Example of pdf generation report from HTML:
import plotly
import xhtml2pdf
from xhtml2pdf import pisa # import python module
graph_block = (''
'<a href="{graph_url}" target="_blank">' # Open the interactive graph when you click on the image
'<img style="height: 400px;" src="{graph_url}.png">'
'</a>')
report_block = ('' +
graph_block +
'{caption}' + # Optional caption to include below the graph
'<br>' + # Line break
'<a href="{graph_url}" style="color: rgb(190,190,190); text-decoration: none; font-weight: 200;" target="_blank">'+
'Click to comment and see the interactive graph' + # Direct readers to Plotly for commenting, interactive graph
'</a>' +
'<br>' +
'<hr>') # horizontal line
# Utility function
def convert_html_to_pdf(source_html, output_filename):
# open output file for writing (truncated binary)
result_file = open(output_filename, "w+b")
# convert HTML to PDF
pisa_status = pisa.CreatePDF(
source_html, # the HTML to convert
dest=result_file) # file handle to recieve result
# close output file
result_file.close() # close output file
# return True on success and False on errors
return pisa_status.err
convert_html_to_pdf(report_block , 'report.pdf')
Example of text in Latex:
import plotly.express as px
fig = px.line(x=[1, 2, 3, 4], y=[1, 4, 9, 16], title=r'$\alpha_{1c} = 352 \pm 11 \text{ km s}^{-1}$')
fig.update_layout(
xaxis_title=r'$\sqrt{(n_\text{c}(t|{T_\text{early}}))}$',
yaxis_title=r'$d, r \text{ (solar radius)}$'
)
fig.show()
Sources:
https://plotly.com/python/v3/pdf-reports/
https://plotly.com/python/LaTeX/