From 0bd8dea3a724fcb2d4ffa3435f00fe45529e7868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=2E=20Brandenburg?= Date: Wed, 24 Nov 2010 14:58:58 -0500 Subject: support plotting histograms --- gnuplot.py | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'gnuplot.py') diff --git a/gnuplot.py b/gnuplot.py index fae329d..a304809 100755 --- a/gnuplot.py +++ b/gnuplot.py @@ -86,14 +86,32 @@ class LiteralGraph(object): (self.expr, title_txt, style_txt) +class HistogramGraph(object): + def __init__(self, fname, col=1, labels_col=None): + self.fname = fname + self.data_col = col + self.labels_col = labels_col + + def __str__(self): + return self.gnuplot_cmd() + + def gnuplot_cmd(self, default_style=None): + if self.labels_col != None: + lstr = ":xticlabels(%s)" % self.labels_col + else: + lstr = "" + return "'%s' using %s%s" % (self.fname, self.data_col, lstr) + + label = Label -def curve(fname=None, literal=None, **kargs): +def curve(fname=None, literal=None, histogram=None, **kargs): if fname: return FileGraph(fname, **kargs) elif literal: return LiteralGraph(literal, **kargs) - + elif histogram: + return HistogramGraph(histogram, **kargs) class Plot(object): def __init__(self): @@ -119,14 +137,24 @@ class Plot(object): self.ylog = None self.ylabel = None + self.boxwidth = None + self.key = None self.title = None self.labels = [] self.curves = [] + self.style = {} self.default_style = None # for plotted curves + def setup_histogram(self, gap=None, boxwidth=0.9): + self.style['data'] = 'histogram' + if gap != None: + self.style['histogram'] = 'cluster gap %s' % gap + self.style['fill'] = 'solid 1.0 border -1' + self.boxwidth = '%.2f relative' % boxwidth + def gnuplot_commands(self, cmd_buf=None): if cmd_buf: g = cmd_buf @@ -198,6 +226,12 @@ class Plot(object): if logscale: g("set logscale %s" % logscale) + if self.boxwidth: + g('set boxwidth %s' % self.boxwidth) + + for s in self.style: + g("set style %s %s" % (s, self.style[s])) + plots = [c.gnuplot_cmd(self.default_style) for c in self.curves] if plots: g("plot " + ", ".join(plots)) -- cgit v1.2.2