From 92e88bb922d5391e30cd5c506da9ebf74b1c0249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=2E=20Brandenburg?= Date: Sun, 28 Mar 2010 00:19:19 -0400 Subject: Introduce CSV-backed graph abstraction. Mostly to support errorbars. --- gnuplot.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/gnuplot.py b/gnuplot.py index 9b5ae11..925b4b3 100755 --- a/gnuplot.py +++ b/gnuplot.py @@ -16,6 +16,32 @@ class CommandBuffer(object): def __str__(self): return '\n'.join([str(x) for x in self.cmds]) +class FileGraph(object): + def __init__(self, fname, xcol=1, ycol=2, error=None, + title=None, + style=None): + self.fname = fname + self.xcol = xcol + self.ycol = ycol + self.error = error + self.title = title + self.style = style + + def __str__(self): + return self.get_command() + + def get_command(self, default_style=None): + if self.error: + using_txt = "%s:%s:%s" % (self.xcol, self.ycol, self.error) + style = self.style if self.style else "errorbars" + else: + using_txt = "%s:%s" % (self.xcol, self.ycol) + style = self.style if self.style else default_style + style_txt = " with %s" % style if style else "" + title_txt = " title '%s'" % self.title if self.title else "" + return "'%s' using %s%s%s" % \ + (self.fname, using_txt, title_txt, style_txt) + def gnuplot_cmd(graphs, title=None, ylabel=None, xlabel=None, format='show', term_opts=None, style='linespoints', xrange=None, @@ -65,7 +91,10 @@ def gnuplot_cmd(graphs, title=None, ylabel=None, xlabel=None, for gr in graphs: if type(gr) == str: # literal plot command - plot.append(gr) + plot.append(str(gr)) + elif type(gr) == FileGraph: + # formatter object + plot.append(gr.get_command(style)) elif len(gr) == 4: par = (gr[0], gr[1], gr[2], gr[3], style) plot += ["'%s' using %s:%s title '%s' with %s" % par] -- cgit v1.2.2