aboutsummaryrefslogtreecommitdiffstats
path: root/gnuplot.py
diff options
context:
space:
mode:
Diffstat (limited to 'gnuplot.py')
-rwxr-xr-xgnuplot.py47
1 files changed, 42 insertions, 5 deletions
diff --git a/gnuplot.py b/gnuplot.py
index ca1e2ff..36ab73c 100755
--- a/gnuplot.py
+++ b/gnuplot.py
@@ -25,14 +25,17 @@ class CommandBuffer(object):
25 25
26 26
27class Label(object): 27class Label(object):
28 def __init__(self, x, y, txt): 28 def __init__(self, x, y, txt, coord=['', ''], align='center'):
29 self.x = x 29 self.x = x
30 self.y = y 30 self.y = y
31 self.txt = txt 31 self.txt = txt
32 # support more label stuff optionally... 32 self.coord = coord
33 self.align = align
34 # support more label stuff optionally...
33 35
34 def gnuplot_cmd(self): 36 def gnuplot_cmd(self):
35 return '"%s" at %f,%f center' % (self.txt, self.x, self.y) 37 return '"%s" at %s %f, %s %f %s' % \
38 (self.txt, self.coord[0], self.x, self.coord[1], self.y, self.align)
36 39
37 def __str__(self): 40 def __str__(self):
38 return 'set label %s' % self.gnuplot_cmd() 41 return 'set label %s' % self.gnuplot_cmd()
@@ -83,14 +86,32 @@ class LiteralGraph(object):
83 (self.expr, title_txt, style_txt) 86 (self.expr, title_txt, style_txt)
84 87
85 88
89class HistogramGraph(object):
90 def __init__(self, fname, col=1, labels_col=None):
91 self.fname = fname
92 self.data_col = col
93 self.labels_col = labels_col
94
95 def __str__(self):
96 return self.gnuplot_cmd()
97
98 def gnuplot_cmd(self, default_style=None):
99 if self.labels_col != None:
100 lstr = ":xticlabels(%s)" % self.labels_col
101 else:
102 lstr = ""
103 return "'%s' using %s%s" % (self.fname, self.data_col, lstr)
104
105
86label = Label 106label = Label
87 107
88def curve(fname=None, literal=None, **kargs): 108def curve(fname=None, literal=None, histogram=None, **kargs):
89 if fname: 109 if fname:
90 return FileGraph(fname, **kargs) 110 return FileGraph(fname, **kargs)
91 elif literal: 111 elif literal:
92 return LiteralGraph(literal, **kargs) 112 return LiteralGraph(literal, **kargs)
93 113 elif histogram:
114 return HistogramGraph(histogram, **kargs)
94 115
95class Plot(object): 116class Plot(object):
96 def __init__(self): 117 def __init__(self):
@@ -116,15 +137,25 @@ class Plot(object):
116 self.ylog = None 137 self.ylog = None
117 self.ylabel = None 138 self.ylabel = None
118 139
140 self.boxwidth = None
141
119 self.key = None 142 self.key = None
120 self.title = None 143 self.title = None
121 144
122 self.labels = [] 145 self.labels = []
123 self.curves = [] 146 self.curves = []
147 self.style = {}
124 148
125 self.default_style = None # for plotted curves 149 self.default_style = None # for plotted curves
126 self.line_styles = [] 150 self.line_styles = []
127 151
152 def setup_histogram(self, gap=None, boxwidth=0.9):
153 self.style['data'] = 'histogram'
154 if gap != None:
155 self.style['histogram'] = 'cluster gap %s' % gap
156 self.style['fill'] = 'solid 1.0 border -1'
157 self.boxwidth = '%.2f relative' % boxwidth
158
128 def gnuplot_commands(self, cmd_buf=None): 159 def gnuplot_commands(self, cmd_buf=None):
129 if cmd_buf: 160 if cmd_buf:
130 g = cmd_buf 161 g = cmd_buf
@@ -196,6 +227,12 @@ class Plot(object):
196 if logscale: 227 if logscale:
197 g("set logscale %s" % logscale) 228 g("set logscale %s" % logscale)
198 229
230 if self.boxwidth:
231 g('set boxwidth %s' % self.boxwidth)
232
233 for s in self.style:
234 g("set style %s %s" % (s, self.style[s]))
235
199 for ls in self.line_styles: 236 for ls in self.line_styles:
200 g("set style line %d %s" % (ls[0], ls[1])) 237 g("set style line %d %s" % (ls[0], ls[1]))
201 238