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, #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
29
|
# File 'lib/simpleplot.rb', line 23
def initialize(name_template="_plot", size = 512)
super()
@name = name_template
@size = size
@series_next = 0;
@metadata = {}
end
|
Instance Method Details
#append_callback(x, y, name, options) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/simpleplot.rb', line 90
def append_callback(x,y,name,options)
xmin = x.min
xmax = x.max
ymin = y.min
ymax = y.max
if !@metadata.has_key?(name)
new_data_callback(name)
end
@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
61
62
63
64
65
66
67
68
|
# File 'lib/simpleplot.rb', line 61
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
70
71
72
|
# File 'lib/simpleplot.rb', line 70
def new_data_callback(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}
end
|
#options_callback(options) ⇒ Object
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
|
# File 'lib/simpleplot.rb', line 31
def options_callback(options)
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['binscount']
end
if options.has_key?('normalized')
@metadata[@current_name]['normalized'] = options['normalized']
end
end
|
#save ⇒ Object
107
108
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
|
# File 'lib/simpleplot.rb', line 107
def save()
data = self.getDataAsXY()
Gnuplot.open do |gp|
data.each do |set_name, series|
Gnuplot::Plot.new(gp) do |plot|
plot.terminal "png"
plot.output "#{set_name+@name}.png"
plot.title set_name
plot.xlabel @metadata[set_name]['xlabel']
plot.ylabel @metadata[set_name]['ylabel']
plot.data = []
if @metadata[set_name]['histogram']
size = @metadata[set_name]['length']
bins = @metadata[set_name]['bincount']
max = @metadata[set_name]['ymax']
min = @metadata[set_name]['ymin']
width = (max-min).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 "[#{@metadata[set_name]['ymin']}:#{@metadata[set_name]['ymax']}]"
end
series.each_with_index do |line, index|
if @metadata[set_name]['histogram']
line = line[1]
end
d = Gnuplot::DataSet.new(line)
d.title = @metadata[set_name]['series_titles'][index]
if @metadata[set_name]['histogram']
d.using = "(#{width}*floor($1/#{width})+#{width}/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
74
75
76
77
78
79
80
81
|
# File 'lib/simpleplot.rb', line 74
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
83
84
85
86
87
88
|
# File 'lib/simpleplot.rb', line 83
def set_y_callback(data, name, options)
ymin = data.min
ymax = data.max
@metadata[name]['ymin'] = ymin
@metadata[name]['ymax'] = ymax
end
|