aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgnuplot.py31
1 files changed, 30 insertions, 1 deletions
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):
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
19class 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
19def gnuplot_cmd(graphs, title=None, ylabel=None, xlabel=None, 45def 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]