grada 2.0.3 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/grada.rb +47 -7
- metadata +1 -1
data/lib/grada.rb
CHANGED
@@ -24,7 +24,16 @@ class Grada
|
|
24
24
|
with: 'lines',
|
25
25
|
graph_type: :default}
|
26
26
|
|
27
|
+
#All styles you can specify for the plots
|
28
|
+
#
|
27
29
|
STYLES = [:linestyle, :linetype, :linewidth, :linecolor, :pointtype, :pointsize, :fill]
|
30
|
+
|
31
|
+
#Graph offsets
|
32
|
+
#
|
33
|
+
LEFT = 0.25
|
34
|
+
RIGHT = 0.25
|
35
|
+
TOP = 0.25
|
36
|
+
BOTTOM = 0.25
|
28
37
|
|
29
38
|
# Hello GraDA
|
30
39
|
#
|
@@ -78,17 +87,21 @@ class Grada
|
|
78
87
|
|
79
88
|
plot_histogram do |plot|
|
80
89
|
plot.set "terminal x11 size #{@opts[:width]},#{@opts[:height]}"
|
90
|
+
plot.set "offset graph #{LEFT},#{RIGHT},#{TOP},#{BOTTOM}"
|
81
91
|
end
|
82
92
|
elsif @opts[:graph_type] == :heatmap
|
83
93
|
Matrix.columns(@x) rescue raise NoPlotDataError
|
84
94
|
@opts[:with] = 'image'
|
85
95
|
|
86
|
-
plot_heat_map
|
96
|
+
plot_heat_map do |plot|
|
97
|
+
plot.set "offset graph #{LEFT},#{RIGHT},#{TOP},#{BOTTOM}"
|
98
|
+
end
|
87
99
|
else
|
88
100
|
raise NoPlotDataError if @y.nil?
|
89
101
|
|
90
102
|
plot_and do |plot|
|
91
103
|
plot.set "terminal x11 size #{@opts[:width]},#{@opts[:height]}"
|
104
|
+
plot.set "offset graph #{LEFT},#{RIGHT},#{TOP},#{BOTTOM}"
|
92
105
|
end
|
93
106
|
end
|
94
107
|
end
|
@@ -114,6 +127,7 @@ class Grada
|
|
114
127
|
plot.output @opts[:filename]
|
115
128
|
plot.set "terminal png size #{@opts[:width]}, #{@opts[:height]} crop"
|
116
129
|
plot.terminal 'png'
|
130
|
+
plot.set "offset graph #{LEFT},#{RIGHT},#{TOP},#{BOTTOM}"
|
117
131
|
end
|
118
132
|
elsif @opts[:graph_type] == :heatmap
|
119
133
|
Matrix.columns(@x) rescue raise NoPlotDataError
|
@@ -123,6 +137,7 @@ class Grada
|
|
123
137
|
plot.output @opts[:filename]
|
124
138
|
plot.set "terminal png size #{@opts[:width]}, #{@opts[:height]} crop"
|
125
139
|
plot.terminal 'png'
|
140
|
+
plot.set "offset graph #{LEFT},#{RIGHT},#{TOP},#{BOTTOM}"
|
126
141
|
end
|
127
142
|
else
|
128
143
|
raise NoPlotDataError if @y.nil?
|
@@ -131,6 +146,7 @@ class Grada
|
|
131
146
|
plot.output @opts[:filename]
|
132
147
|
plot.set "terminal png size #{@opts[:width]}, #{@opts[:height]} crop"
|
133
148
|
plot.terminal 'png'
|
149
|
+
plot.set "offset graph #{LEFT},#{RIGHT},#{TOP},#{BOTTOM}"
|
134
150
|
end
|
135
151
|
end
|
136
152
|
end
|
@@ -199,8 +215,16 @@ class Grada
|
|
199
215
|
else
|
200
216
|
raise NoPlotDataError if ! @y.nil? && @x.size != @y.size
|
201
217
|
|
218
|
+
style = Gnuplot::Style.new do |ds|
|
219
|
+
ds.index = index
|
220
|
+
STYLES.each do |style|
|
221
|
+
ds.send("#{style}=", dic[style]) if dic[style]
|
222
|
+
end
|
223
|
+
end.to_s
|
224
|
+
|
202
225
|
plot.data << Gnuplot::DataSet.new([@x,@y]) do |ds|
|
203
226
|
ds.with = @opts[:with]
|
227
|
+
ds.with += style
|
204
228
|
end
|
205
229
|
end
|
206
230
|
end
|
@@ -211,17 +235,33 @@ class Grada
|
|
211
235
|
Gnuplot.open do |gp|
|
212
236
|
Gnuplot::Plot.new(gp) do |plot|
|
213
237
|
block[plot] if block
|
238
|
+
|
239
|
+
width = ( @x.max - @x.min ) / @x.size
|
214
240
|
|
215
241
|
plot.title @opts[:title]
|
216
242
|
|
217
243
|
plot.set "style data histogram"
|
218
244
|
plot.xlabel @opts[:x_label]
|
219
|
-
plot.ylabel "
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
plot.
|
224
|
-
|
245
|
+
plot.ylabel "Frequency"
|
246
|
+
plot.set "style fill solid 0.5"
|
247
|
+
plot.set "xrange [#{@x.min}:#{@x.max}]"
|
248
|
+
plot.set "boxwidth #{ width * 0.4}"
|
249
|
+
plot.set "xtics #{@x.min},#{(@x.max-@x.min)/5},#{@x.max}"
|
250
|
+
plot.set "tics out nomirror"
|
251
|
+
|
252
|
+
style = Gnuplot::Style.new do |ds|
|
253
|
+
ds.index = index
|
254
|
+
STYLES.each do |style|
|
255
|
+
ds.send("#{style}=", dic[style]) if dic[style]
|
256
|
+
end
|
257
|
+
end.to_s
|
258
|
+
|
259
|
+
plot.data << Gnuplot::DataSet.new(@x) do |ds|
|
260
|
+
ds.with = 'boxes'
|
261
|
+
ds.with += style
|
262
|
+
ds.title = @opts[:x_label]
|
263
|
+
ds.using = '($1):(1.0)'
|
264
|
+
ds.smooth = 'freq'
|
225
265
|
end
|
226
266
|
end
|
227
267
|
end
|