ruby-plot 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/plot_points.rb +61 -27
  3. metadata +5 -5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.4.0
data/lib/plot_points.rb CHANGED
@@ -8,20 +8,14 @@
8
8
 
9
9
  module RubyPlot
10
10
 
11
- def self.plot_points(path, title, x_lable, y_lable, names, x_values, y_values, log=true)
12
-
13
- LOGGER.debug "ruby-plot: plot points "+names.inspect
14
- LOGGER.debug "ruby-plot: plot points "+x_values.inspect
15
- LOGGER.debug "ruby-plot: plot points "+y_values.inspect
11
+ def self.regression_point_plot(path, title, x_lable, y_lable, names, x_values, y_values, log=true) #, quadratic_scale=true, line_points=false, reverse_x=false)
16
12
 
17
13
  min = Float::MAX
18
14
  max = -Float::MAX
19
-
20
15
  data = []
21
16
  (0..x_values.size-1).each do |i|
22
17
  data << y_values[i]
23
18
  data << x_values[i]
24
-
25
19
  min = [ min, x_values[i].min, y_values[i].min ].min
26
20
  max = [ max, x_values[i].max, y_values[i].max ].max
27
21
  end
@@ -31,6 +25,43 @@ module RubyPlot
31
25
  log = false
32
26
  end
33
27
 
28
+ border = (max-min)*0.1
29
+ if log
30
+ min_border = min-border/10.0
31
+ while min_border<=0
32
+ border /= 2
33
+ min_border = min-border/10.0
34
+ end
35
+ max_border = max+border
36
+ else
37
+ min_border = min-border
38
+ max_border = max+border
39
+ end
40
+
41
+ x_range = [min_border, max_border]
42
+ y_range = [min_border, max_border]
43
+
44
+ plot_points(path, title, x_lable, y_lable, names, x_values, y_values, log, x_range, y_range, true, true, false, false, false)
45
+ end
46
+
47
+ def self.accuracy_confidence_plot(path, title, x_lable, y_lable, names, x_values, y_values, y_range=nil, reverse_y=false)
48
+
49
+ plot_points(path, title, x_lable, y_lable, names, x_values, y_values, false, nil, y_range, false, false, true, true, reverse_y)
50
+ end
51
+
52
+ def self.plot_points(path, title, x_lable, y_lable, names, x_values, y_values,
53
+ log=true, x_range=nil, y_range=nil, quadratic_scale=true, draw_diagonale=true, line_points=false, reverse_x=false, reverse_y=false)
54
+
55
+ LOGGER.debug "ruby-plot: plot points "+names.inspect
56
+ LOGGER.debug "ruby-plot: plot points "+x_values.inspect
57
+ LOGGER.debug "ruby-plot: plot points "+y_values.inspect
58
+
59
+ data = []
60
+ (0..x_values.size-1).each do |i|
61
+ data << y_values[i]
62
+ data << x_values[i]
63
+ end
64
+
34
65
  #Main
35
66
  STDOUT.sync = true
36
67
  # -----------------------------------------------------
@@ -121,8 +152,6 @@ module RubyPlot
121
152
  else
122
153
  raise "format not supported "+path.to_s
123
154
  end
124
- # x and y have equal scale
125
- output_plt_arr.push 'set size ratio -1'
126
155
 
127
156
  if log
128
157
  output_plt_arr.push 'set logscale x'
@@ -133,20 +162,15 @@ module RubyPlot
133
162
  output_plt_arr.push ""
134
163
  output_plt_arr.push "# Specifies the range of the axes and appearance"
135
164
 
136
- border = (max-min)*0.1
137
- if log
138
- min_border = min-border/10.0
139
- while min_border<=0
140
- border /= 2
141
- min_border = min-border/10.0
142
- end
143
- max_border = max+border
144
- else
145
- min_border = min-border
146
- max_border = max+border
147
- end
148
- output_plt_arr.push "set xrange ["+min_border.to_s+":"+max_border.to_s+"]"
149
- output_plt_arr.push "set yrange ["+min_border.to_s+":"+max_border.to_s+"]"
165
+ x_range_s = x_range ? "["+x_range[0].to_s+":"+x_range[1].to_s+"]" : "[]"
166
+ y_range_s = y_range ? "["+y_range[0].to_s+":"+y_range[1].to_s+"]" : "[]"
167
+ reverse_x_s = reverse_x ? "reverse" : ""
168
+ reverse_y_s = reverse_y ? "reverse" : ""
169
+ output_plt_arr.push "set xrange "+x_range_s+" "+reverse_x_s
170
+ output_plt_arr.push "set yrange "+y_range_s+" "+reverse_y_s
171
+
172
+ output_plt_arr.push 'set size ratio -1' if quadratic_scale
173
+ output_plt_arr.push "set arrow from "+x_range[0].to_s+","+y_range[0].to_s+" to "+x_range[1].to_s+","+y_range[1].to_s+" nohead lt 0" if draw_diagonale
150
174
 
151
175
  output_plt_arr.push "set grid lw 0.5"
152
176
  output_plt_arr.push "set title \"#{title}\""
@@ -154,7 +178,7 @@ module RubyPlot
154
178
  output_plt_arr.push "set xlabel \"#{x_lable}\""
155
179
  output_plt_arr.push "set ylabel \"#{y_lable}\""
156
180
 
157
- output_plt_arr.push "set arrow from "+min_border.to_s+","+min_border.to_s+" to "+max_border.to_s+","+max_border.to_s+" nohead lt 0"
181
+
158
182
  output_plt_arr.push ""
159
183
  output_plt_arr.push ""
160
184
  output_plt_arr.push ""
@@ -162,12 +186,18 @@ module RubyPlot
162
186
  output_plt_arr.push "# Draws the plot and specifies its appearance ..."
163
187
 
164
188
  output_plt_arr.push "plot \\"#'random_0.dat' using 1:2 title 'random' with lines lw 1, \\"
189
+
190
+ style = "points"
191
+ if (line_points)
192
+ style = "lp"
193
+ end
194
+
165
195
  i = 0
166
196
  for i in 0..names.length-1
167
197
  if i == names.length-1
168
- output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{names[i]}' with points"
198
+ output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{names[i]}' with "+style.to_s
169
199
  else
170
- output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{names[i]}' with points, \\"
200
+ output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{names[i]}' with "+style.to_s+", \\"
171
201
  end
172
202
  end
173
203
  output_plt_arr.push ""
@@ -209,9 +239,13 @@ module RubyPlot
209
239
  end
210
240
 
211
241
  def self.test_plot_points
212
- plot_points("/tmp/result.png" , "name of title", "x-values", "y-values", ["this-one-has-a-very-very-very-long-name", "test" ],
242
+ regression_point_plot("/tmp/regression.png" , "name of title", "x-values", "y-values", ["this-one-has-a-very-very-very-long-name", "test" ],
213
243
  [[0.20,0.60,0.80,0.20,1.0,0.001], [0.10,0.25,0.70,0.95,0.2,0.3434]],
214
244
  [[0.15,0.50,0.90,0.2,9,0.5],[0.20,0.40,0.50,0.70,0.3,0.234589]])
245
+
246
+ accuracy_confidence_plot("/tmp/accuracy-conf.png" , "name of title", "x-values", "y-values", ["test" ],
247
+ [[0.9,0.5,0.3,0.1]],
248
+ [[100,90,70,30]])
215
249
  end
216
250
 
217
251
  private
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-plot
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Vorgrimmler
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-13 00:00:00 +02:00
19
+ date: 2011-05-16 00:00:00 +02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency