37 lines
963 B
Python
37 lines
963 B
Python
# -*- encoding: utf-8 -*-
|
|
|
|
from ..element import element
|
|
|
|
|
|
class generic_plot(element):
|
|
""" Class representing a pgfplots plot. """
|
|
|
|
templates = {
|
|
'options': '+[{content}]',
|
|
'content': """\\addplot{options} {data};"""
|
|
}
|
|
|
|
def __init__(self, legend, data, label=None, options=[]):
|
|
super().__init__(label=label)
|
|
self.legend = legend
|
|
self.data = data
|
|
self.options = options
|
|
|
|
def format_options(self, options):
|
|
if not options:
|
|
return ''
|
|
opts = []
|
|
for opt in options:
|
|
if type(opt) is not str:
|
|
opt = '{}={}'.format(*opt)
|
|
opts.append(str(opt))
|
|
return self.fmt().format('options', {
|
|
'content': ', '.join(opts)
|
|
})
|
|
|
|
def content(self):
|
|
return self.fmt().format('content', {
|
|
'data': self.format_data(self.data),
|
|
'options': self.format_options(self.options)
|
|
})
|