46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
# -*- encoding: utf-8 -*-
|
|
|
|
from ..formatter import formatter
|
|
|
|
|
|
class axis:
|
|
""" Class representing an axis. """
|
|
|
|
fmt = formatter({
|
|
'options': '[{content}]',
|
|
'legends': '\\legend{{{content}}}',
|
|
'content': """\\begin{{axis}}{options}
|
|
{inner}
|
|
{legend}
|
|
\\end{{axis}}"""
|
|
})
|
|
|
|
def __init__(self, *args, **kargs):
|
|
self.options = kargs
|
|
self.plots = []
|
|
for arg in args:
|
|
self.addplot(arg)
|
|
|
|
def addplot(self, pl):
|
|
self.plots.append(pl)
|
|
|
|
def format_options(self, options):
|
|
if not options:
|
|
return ''
|
|
opts = []
|
|
for k, v in options.items():
|
|
opts.append('{key} = {{{value}}}'.format(key=k, value=v))
|
|
return self.fmt.format('options', {
|
|
'content': ', '.join(opts)
|
|
})
|
|
|
|
def __str__(self):
|
|
return self.fmt.format('content', {
|
|
'options': self.format_options(self.options),
|
|
'inner': '\n'.join(map(str, self.plots)),
|
|
'legend': self.fmt.format('legends', {
|
|
'content': ', '.join('{{{}}}'.format(p.legend)
|
|
for p in self.plots)
|
|
})
|
|
})
|