Add possibility to specify custom options for pgfplots elements.
This commit is contained in:
parent
758e99d5a7
commit
8a8cb4d177
@ -15,9 +15,9 @@ class axis(element):
|
||||
\\end{{axis}}"""
|
||||
}
|
||||
|
||||
def __init__(self, *args, parent=None, legend=True, label=None, **kargs):
|
||||
def __init__(self, *args, parent=None, legend=True, label=None, **kwargs):
|
||||
super().__init__(parent, label=label)
|
||||
self.options = kargs
|
||||
self.options = kwargs
|
||||
self.legend = legend
|
||||
for arg in args:
|
||||
self.add(arg)
|
||||
|
@ -11,5 +11,6 @@ class coordinates_plot(generic_plot):
|
||||
def format_data(self, data):
|
||||
pts = []
|
||||
for d in data:
|
||||
pts.append('({}, {})'.format(*d))
|
||||
pts.append('({}, {})'.format(
|
||||
*self.format_values(d)))
|
||||
return 'coordinates {{{}}}'.format(''.join(pts))
|
||||
|
@ -5,7 +5,7 @@ from .generic_plot import generic_plot
|
||||
|
||||
class errorbars_plot(generic_plot):
|
||||
|
||||
def __init__(self, legend, data, label=None, options=[]):
|
||||
def __init__(self, legend, data, precision=5, label=None, options=[]):
|
||||
options = options + [
|
||||
'error bars/.cd', ('y dir', 'both'), ('y explicit')]
|
||||
super().__init__(legend, data, label=label, options=options)
|
||||
@ -20,5 +20,6 @@ class errorbars_plot(generic_plot):
|
||||
p = d[2]
|
||||
n = p
|
||||
rows.append('({x}, {y}) += (0, {p}) -= (0, {n})'.format(
|
||||
x=x, y=y, p=p, n=n))
|
||||
x=self.format_value(x), y=self.format_value(y),
|
||||
p=self.format_value(p), n=self.format_value(n)))
|
||||
return 'coordinates {{{}}}'.format('\n'.join(rows))
|
||||
|
@ -11,11 +11,12 @@ class generic_plot(element):
|
||||
'content': """\\addplot{options} {data};"""
|
||||
}
|
||||
|
||||
def __init__(self, legend, data, label=None, options=[]):
|
||||
def __init__(self, legend, data, precision=6, label=None, options=[]):
|
||||
super().__init__(label=label)
|
||||
self.legend = legend
|
||||
self.data = data
|
||||
self.options = options
|
||||
self.precision = precision
|
||||
|
||||
def format_options(self, options):
|
||||
if not options:
|
||||
@ -29,6 +30,12 @@ class generic_plot(element):
|
||||
'content': ', '.join(opts)
|
||||
})
|
||||
|
||||
def format_value(self, value):
|
||||
return '{:.{prec}f}'.format(value, prec=self.precision)
|
||||
|
||||
def format_values(self, values):
|
||||
return [self.format_value(value) for value in values]
|
||||
|
||||
def content(self):
|
||||
return self.fmt().format('content', {
|
||||
'data': self.format_data(self.data),
|
||||
|
Loading…
Reference in New Issue
Block a user