我想使用 python 创建出版物质量表以输出为 svg 或 jpg 或 png 图像。
我熟悉 texttable 模块,它可以生成漂亮的文本表,但是如果我有例如
data = [['Head 1','Head 2','Head 3'],['Sample Set Type 1',12.8,True],['Sample Set Type 2',15.7,False]]
我想制作一些看起来像这样的东西
有我可以求助的模块吗?或者您能给我指出一个处理该问题的流程吗?
你有很多可能性。
您可以按照 https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_latex.html
将 Pandas 数据框转换为 Latex您还可以使用表格输出乳胶源,按照http://en.wikibooks.org/wiki/LaTeX/Tables
您可以使用 ReportLab,按照 Python reportlab 将图像插入表格
您也可以编写一个 HTML 表格文件并使用 css 对其进行样式设置。
with open("example.html", "w") as of:
of.write("<html><table>")
for index, row in enumerate(data):
if index == 0:
of.write("<th>")
else:
of.write("<tr>")
for cell in row:
of.write("<td>" + cell + "</td>")
if index == 0:
of.write("</th>")
else:
of.write("</tr>")
of.write("</table></html>")
您可以使用 Latex 表作为输出执行类似的操作。
多年后的自我编辑: Rich 的表格非常适合 shell 中的表格:https://rich.readthedocs.io/en/stable/tables.html