在python中创建出版质量表 [英] Creating publication quality tables in python

查看:29
本文介绍了在python中创建出版质量表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 python 创建出版物质量表,以输出为 svg 或 jpg 或 png 图像.

I'd like to create publication quality tables for output as svg or jpg or png images using python.

我熟悉生成漂亮文本表格的 texttable 模块,但如果我有例如

I'm familiar with the texttable module which produces nice text tables but if I have for example

data = [['Head 1','Head 2','Head 3'],['Sample Set Type 1',12.8,True],['Sample Set Type 2',15.7,False]]

我想制作看起来像的东西

and I wanted to produce something that looked like

是否有我可以参考的模块,或者您能否为我指出一个流程?

Is there a module I can turn to, or can you point me to a process for going about it?

推荐答案

感觉就像是一份 http://matplotlib.org 的工作/,根据 https://stackoverflow.com/a/8976359/447599.

Feels like a job for http://matplotlib.org/, as per https://stackoverflow.com/a/8976359/447599.

也可能是 ReportLab 的工作,根据 Python 报告实验室将图像插入表格

Could also be a job for ReportLab, as per Python reportlab inserting image into table

另一种选择是按照 http://en 使用表格输出乳胶源.wikibooks.org/wiki/LaTeX/Tables

如果这不适合您,只需编写 .csv 文件并在 excel 中格式化表格,然后在那里导出图像形式,代码如下

If that doesn't suit you, just write .csv files and format the table in excel, and export the image form there, with code like

with open("example.csv") as of:
    for row in data:
        for cell in row:
             of.write(cell + ";")
        of.write("\n")

我想你也可以只写一个 html 表格文件并用 css 设置样式.

I guess you could also just write an html table file and style it with css.

with open("example.html") 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>")

这篇关于在python中创建出版质量表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆