Class: SimplePlot
Overview
SimplePlot
GnuPlot interface to simpleoutput
Copyright 2014 Austen Higgins-Cassidy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Instance Method Summary
collapse
#advance_series, #annotate, #appendHash, #appendPoints, #appendXY, #append_series_name, #getDataAsPoints, #getDataAsXY, #getSeriesHashes, #newData, #new_data_check, #setHash, #setOptions, #setPoints, #setXData, #setXY, #setYData, #translate_name
Constructor Details
#initialize(name_template = "_plot", size = 512) ⇒ SimplePlot
Returns a new instance of SimplePlot.
23
24
25
26
27
28
|
# File 'lib/simpleplot.rb', line 23
def initialize(name_template="_plot", size = 512)
super()
@name = name_template
@size = size
@series_next = 0;
end
|
Instance Method Details
#append_callback(x, y, name, options) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/simpleplot.rb', line 96
def append_callback(x,y,name,options)
xmin = x.min
xmax = x.max
ymin = y.min
ymax = y.max
@metadata[name]['length'] = @metadata[name]['length'] < x.size ? x.size : @metadata[name]['length']
@metadata[name]['xmin'] = xmin < @metadata[name]['xmin'] ? xmin : @metadata[name]['xmin']
@metadata[name]['xmax'] = xmax > @metadata[name]['xmax'] ? xmax : @metadata[name]['xmax']
@metadata[name]['ymin'] = ymin < @metadata[name]['ymin'] ? ymin : @metadata[name]['ymin']
@metadata[name]['ymax'] = ymax > @metadata[name]['ymax'] ? ymax : @metadata[name]['ymax']
check_title(name, options)
end
|
#check_title(name, options) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/simpleplot.rb', line 66
def check_title(name, options)
if options.has_key?('series')
@metadata[name]['series_titles'] << options['series']
else
@metadata[name]['series_titles'] << "set-#{@series_next}"
@series_next += 1
end
end
|
#new_data_callback(name) ⇒ Object
75
76
77
78
|
# File 'lib/simpleplot.rb', line 75
def new_data_callback(name)
name = translate_name(name)
@metadata[name] = {'length' => 0, 'xlabel' => 'x', 'ylabel' => 'y', 'xmin' => 0 , 'xmax' => 10, 'ymin' => 0, 'ymax' => 10, 'series_titles' => [], 'histogram' => false, 'bincount' => 10, 'normalized' => false, 'xsize' => 640, 'ysize' => 480}
end
|
#options_callback(options) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/simpleplot.rb', line 30
def options_callback(options)
if options.has_key?('xsize')
@metadata[@current_name]['xsize'] = options['xsize']
end
if options.has_key?('ysize')
@metadata[@current_name]['ysize'] = options['ysize']
end
if options.has_key?('xlabel')
@metadata[@current_name]['xlabel'] = options['xlabel']
end
if options.has_key?('ylabel')
@metadata[@current_name]['ylabel'] = options['ylabel']
end
if options.has_key?('histogram')
@metadata[@current_name]['histogram'] = options['histogram']
end
if options.has_key?('xmin')
@metadata[@current_name]['xmin'] = options['xmin']
end
if options.has_key?('xmax')
@metadata[@current_name]['xmax'] = options['xmax']
end
if options.has_key?('ymin')
@metadata[@current_name]['ymin'] = options['ymin']
end
if options.has_key?('ymax')
@metadata[@current_name]['ymax'] = options['ymax']
end
if options.has_key?('bincount')
@metadata[@current_name]['bincount'] = options['bincount']
end
if options.has_key?('normalized')
@metadata[@current_name]['normalized'] = options['normalized']
end
end
|
#save ⇒ Object
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
# File 'lib/simpleplot.rb', line 109
def save()
data = self.getDataAsXY()
data.each do |set_name, series|
Gnuplot.open do |gp|
Gnuplot::Plot.new(gp) do |plot|
plot.terminal "png size #{@metadata[set_name]['xsize']},#{@metadata[set_name]['ysize']}"
plot.output "#{set_name+@name}.png"
plot.title set_name
plot.xlabel @metadata[set_name]['xlabel']
plot.ylabel @metadata[set_name]['ylabel']
plot.data = []
max = @metadata[set_name]['ymax']
min = @metadata[set_name]['ymin']
if min == max
max = min + 1
end
if @metadata[set_name]['histogram']
size = @metadata[set_name]['length']
bins = @metadata[set_name]['bincount']
width = (max.to_f-min.to_f).to_f/bins.to_f
plot.yrange '[0:]'
plot.xrange "[#{min}:#{max}]"
plot.set('boxwidth',width*0.9)
plot.set('offset', 'graph 0.05,0.05,0.05,0.0')
plot.set('xtics' " #{min}, #{width.to_f}, #{max}")
plot.set('tics', 'out nomirror')
plot.set('style', 'fill solid 0.5')
else
plot.xrange "[#{@metadata[set_name]['xmin']}:#{@metadata[set_name]['xmax']}]"
plot.yrange "[#{min}:#{max}]"
end
series.each_with_index do |line, index|
if @metadata[set_name]['histogram']
data_pts = line[1]
else
data_pts = line
end
d = Gnuplot::DataSet.new(data_pts)
d.title = @metadata[set_name]['series_titles'][index]
if @metadata[set_name]['histogram']
d.using = "(#{width.to_f}*floor($1/#{width.to_f})+#{width.to_f}/2.0):(1.0) smooth freq w boxes lc rgb\"blue\""
else
d.with = "linespoints"
d.linewidth = 2
end
plot.data << d
end
end
end
end
end
|
#set_x_callback(data, name, options) ⇒ Object
80
81
82
83
84
85
86
87
|
# File 'lib/simpleplot.rb', line 80
def set_x_callback(data, name, options)
xmin = data.min
xmax = data.max
@metadata[name]['xmin'] = xmin
@metadata[name]['xmax'] = xmax
@metadata[name]['length'] = (@metadata[name]['length'] < data.size) ? data.size : @metadata[name]['length']
check_title(name, options)
end
|
#set_y_callback(data, name, options) ⇒ Object
89
90
91
92
93
94
|
# File 'lib/simpleplot.rb', line 89
def set_y_callback(data, name, options)
ymin = data.min
ymax = data.max
@metadata[name]['ymin'] = ymin
@metadata[name]['ymax'] = ymax
end
|