pyltk/tests/test_basic.py

81 lines
1.9 KiB
Python

# -*- encoding: utf-8 -*-
import os
import sys
sys.path += ['..']
from pyltk import subfloat, tabular, resizebox, makebox, figure
from pyltk.tikz import tikzpicture
from pyltk.pgfplots import axis, errorbars_plot, coordinates_plot
if __name__ == "__main__":
data = [[1.00000000e+00,
4.57213083e+00],
[2.00000000e+00,
1.16046200e+01],
[4.00000000e+00,
2.71873880e+01],
[ 5.00000000e+00,
3.36039380e+01],
[ 1.00000000e+01,
7.21689923e+01],
[ 2.00000000e+01,
1.50422028e+02]]
tk1 = tikzpicture()
tk1.add(axis(coordinates_plot('test', data),
xlabel='', ylabel='Computation Time [s]'))
tk2 = tikzpicture()
tk2.add(axis(errorbars_plot('test 2', [
[0, 5, (2, 3)],
[1, 8, (4, 5)]
])))
tk3 = tikzpicture()
tk3.add(axis(errorbars_plot('test 2', [
[0, 5, 3],
[4, 8, 4]
])))
tk4 = tikzpicture()
tk4.add(axis(coordinates_plot('test', [])))
s1 = subfloat('Caption 1', childrens=tk1)
s2 = subfloat('Caption 2', childrens=tk2)
s3 = subfloat('Caption 3', childrens=tk3)
s4 = subfloat('Caption 4', childrens=tk4)
tab = tabular(rows=[
[s1, s2],
[s3, s4]
], columns='cc', autowrap=resizebox)
f = figure(makebox(tab), '!h')
print(f) # f.childrens[0].childrens[0].childrens)
wrap = """\\documentclass{{article}}
\\usepackage{{amsmath,amsfonts,amssymb}}
\\usepackage{{tabularx}}
\\usepackage{{multirow}}
\\usepackage{{stmaryrd}}
\\usepackage{{hhline}}
\\usepackage{{caption}}
\\usepackage{{tikz}}
\\usetikzlibrary{{arrows}}
\\usetikzlibrary{{positioning}}
\\usepackage{{subfig}}
\\usepackage{{pgfplots}}
\\begin{{document}}
{content}
\\end{{document}}""".format(content=f)
with open('/tmp/test.tex', 'w') as fd:
fd.write(wrap)
os.system('pdflatex /tmp/test.tex')
os.system('evince test.pdf')