diff options
author | Björn B. Brandenburg <bbb@cs.unc.edu> | 2010-03-28 00:19:19 -0400 |
---|---|---|
committer | Björn B. Brandenburg <bbb@cs.unc.edu> | 2010-03-28 00:19:19 -0400 |
commit | 92e88bb922d5391e30cd5c506da9ebf74b1c0249 (patch) | |
tree | 3da0ec0822e286dc43c9fb6c2f83dbbe92d2b768 | |
parent | 4bff8dc35059f69e79d75b679a0e28cca5322785 (diff) |
Introduce CSV-backed graph abstraction.
Mostly to support errorbars.
-rwxr-xr-x | gnuplot.py | 31 |
1 files changed, 30 insertions, 1 deletions
@@ -16,6 +16,32 @@ class CommandBuffer(object): | |||
16 | def __str__(self): | 16 | def __str__(self): |
17 | return '\n'.join([str(x) for x in self.cmds]) | 17 | return '\n'.join([str(x) for x in self.cmds]) |
18 | 18 | ||
19 | class FileGraph(object): | ||
20 | def __init__(self, fname, xcol=1, ycol=2, error=None, | ||
21 | title=None, | ||
22 | style=None): | ||
23 | self.fname = fname | ||
24 | self.xcol = xcol | ||
25 | self.ycol = ycol | ||
26 | self.error = error | ||
27 | self.title = title | ||
28 | self.style = style | ||
29 | |||
30 | def __str__(self): | ||
31 | return self.get_command() | ||
32 | |||
33 | def get_command(self, default_style=None): | ||
34 | if self.error: | ||
35 | using_txt = "%s:%s:%s" % (self.xcol, self.ycol, self.error) | ||
36 | style = self.style if self.style else "errorbars" | ||
37 | else: | ||
38 | using_txt = "%s:%s" % (self.xcol, self.ycol) | ||
39 | style = self.style if self.style else default_style | ||
40 | style_txt = " with %s" % style if style else "" | ||
41 | title_txt = " title '%s'" % self.title if self.title else "" | ||
42 | return "'%s' using %s%s%s" % \ | ||
43 | (self.fname, using_txt, title_txt, style_txt) | ||
44 | |||
19 | def gnuplot_cmd(graphs, title=None, ylabel=None, xlabel=None, | 45 | def gnuplot_cmd(graphs, title=None, ylabel=None, xlabel=None, |
20 | format='show', term_opts=None, | 46 | format='show', term_opts=None, |
21 | style='linespoints', xrange=None, | 47 | style='linespoints', xrange=None, |
@@ -65,7 +91,10 @@ def gnuplot_cmd(graphs, title=None, ylabel=None, xlabel=None, | |||
65 | for gr in graphs: | 91 | for gr in graphs: |
66 | if type(gr) == str: | 92 | if type(gr) == str: |
67 | # literal plot command | 93 | # literal plot command |
68 | plot.append(gr) | 94 | plot.append(str(gr)) |
95 | elif type(gr) == FileGraph: | ||
96 | # formatter object | ||
97 | plot.append(gr.get_command(style)) | ||
69 | elif len(gr) == 4: | 98 | elif len(gr) == 4: |
70 | par = (gr[0], gr[1], gr[2], gr[3], style) | 99 | par = (gr[0], gr[1], gr[2], gr[3], style) |
71 | plot += ["'%s' using %s:%s title '%s' with %s" % par] | 100 | plot += ["'%s' using %s:%s title '%s' with %s" % par] |