ruby-plot 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -14,7 +14,14 @@ module RubyPlot
14
14
  string += '"' + measures[i-1] + '" ' + i.to_s + ".00000 -1 "
15
15
  end
16
16
 
17
- plot.terminal 'svg size 800,600 dynamic enhanced fname "Arial" fsize 12 butt'
17
+ if output_file=~/(?i)svg/
18
+ plot.terminal 'svg size 800,600 dynamic enhanced fname "Arial" fsize 12 butt'
19
+ elsif output_file=~/(?i)png/
20
+ plot.terminal 'png'
21
+ else
22
+ raise "format not supported "+path.to_s
23
+ end
24
+
18
25
  plot.output output_file
19
26
  plot.bar '1.000000'
20
27
  plot.boxwidth '0.9 absolute'
@@ -58,6 +65,10 @@ module RubyPlot
58
65
  x = ['ACC_with_very_long_name_consider_that', 'AUC', 'SPEC', 'SENS']
59
66
  data = [['Alg1', 1.00, 1.00, 1.00, 1.00], ['Alg2', 0.75, 0.75, 0.75, 0.75], ['Alg3', 0.50, 0.50, 0.50, 0.50]]
60
67
  plot_bars('Vergleich der Algorithmen', x, data, '/tmp/hist.svg')
68
+
69
+ x = ['ACC_with_very_long_name_consider_that', 'AUC', 'SPEC', 'SENS']
70
+ data = [['Alg1', 1.00, 1.00, 1.00, 1.00], ['Alg2', 0.75, 0.75, 0.75, 0.75], ['Alg3', 0.50, 0.50, 0.50, 0.50]]
71
+ plot_bars('Vergleich der Algorithmen', x, data, '/tmp/hist.png')
61
72
  end
62
73
 
63
74
  end
@@ -8,7 +8,7 @@
8
8
 
9
9
  module RubyPlot
10
10
 
11
- def self.plot_lines(svg_path, title, x_lable, y_lable, names, x_values, y_values, faint=nil)
11
+ def self.plot_lines(path, title, x_lable, y_lable, names, x_values, y_values, faint=nil)
12
12
 
13
13
  #LOGGER.debug names.inspect
14
14
  #LOGGER.debug x_values.inspect
@@ -37,7 +37,7 @@ module RubyPlot
37
37
  end
38
38
 
39
39
  if status
40
- raise "Usage: svg_roc_plot (svg_path(?), title(string), x-lable(string), y-lable(sting), algorithms(array), true_pos_data1(array), false_pos_data1(array), ..., true_pos_data_n(array), false_pos_data_n(array))\n"+
40
+ raise "Usage: svg_roc_plot (path(?), title(string), x-lable(string), y-lable(sting), algorithms(array), true_pos_data1(array), false_pos_data1(array), ..., true_pos_data_n(array), false_pos_data_n(array))\n"+
41
41
  " Only pairs of data are allowed but at least one.\n"+
42
42
  " Each data array has to provide one float/int number from 0 to 100 per entry."
43
43
  end
@@ -103,11 +103,20 @@ module RubyPlot
103
103
  output_plt_arr.push "# Specifies encoding and output format"
104
104
  output_plt_arr.push "set encoding default"
105
105
  #output_plt_arr.push "set terminal svg"
106
- output_plt_arr.push 'set terminal svg size 800,600 dynamic enhanced fname "Arial" fsize 12 butt'
107
- output_plt_arr.push "set output '#{svg_path}'"
106
+ if path=~/(?i)svg/
107
+ output_plt_arr.push 'set terminal svg size 800,600 dynamic enhanced fname "Arial" fsize 12 butt'
108
+ elsif path=~/(?i)png/
109
+ output_plt_arr.push 'set terminal png'
110
+ else
111
+ raise "format not supported "+path.to_s
112
+ end
113
+ output_plt_arr.push "set output '#{path}'"
108
114
  output_plt_arr.push ""
109
115
  output_plt_arr.push "# Specifies the range of the axes and appearance"
110
116
 
117
+ # x and y have equal scale
118
+ output_plt_arr.push 'set size ratio -1'
119
+
111
120
  output_plt_arr.push "set xrange [0:100]"
112
121
  output_plt_arr.push "set yrange [0:100]"
113
122
  output_plt_arr.push "set grid lw 0.5"
@@ -157,7 +166,7 @@ module RubyPlot
157
166
  end
158
167
  raise "gnuplot failes (cmd: "+cmd.to_s+", out: "+response.to_s+")" unless $?==0
159
168
 
160
- LOGGER.debug "#{svg_path} created. "
169
+ LOGGER.debug "#{path} created. "
161
170
 
162
171
  # -----------------------------------------------------
163
172
  # remove *.plt and *.dat files
@@ -172,6 +181,8 @@ module RubyPlot
172
181
 
173
182
  def self.test_plot_lines
174
183
  plot_lines("/tmp/result.svg" , "name of title", "x-values", "y-values", ["name", "test", "bla"], [[20,60,80], [10,25,70,95], [12,78,99]], [[15,50,90],[20,40,50,70],[34,89,89]],[true,false,true])
184
+
185
+ plot_lines("/tmp/result.png" , "name of title", "x-values", "y-values", ["name", "test", "bla"], [[20,60,80], [10,25,70,95], [12,78,99]], [[15,50,90],[20,40,50,70],[34,89,89]],[true,false,true])
175
186
  end
176
187
 
177
188
  private
@@ -8,16 +8,27 @@
8
8
 
9
9
  module RubyPlot
10
10
 
11
- def self.plot_points(svg_path, title, x_lable, y_lable, names, x_values, y_values)
11
+ def self.plot_points(path, title, x_lable, y_lable, names, x_values, y_values, log=true)
12
12
 
13
- LOGGER.debug names.inspect
14
- LOGGER.debug x_values.inspect
15
- LOGGER.debug y_values.inspect
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
16
+
17
+ min = Float::MAX
18
+ max = -Float::MAX
16
19
 
17
20
  data = []
18
21
  (0..x_values.size-1).each do |i|
19
22
  data << y_values[i]
20
23
  data << x_values[i]
24
+
25
+ min = [ min, x_values[i].min, y_values[i].min ].min
26
+ max = [ max, x_values[i].max, y_values[i].max ].max
27
+ end
28
+
29
+ if log && min<=0
30
+ LOGGER.warn "cannot use logscale for <=0 data"
31
+ log = false
21
32
  end
22
33
 
23
34
  #Main
@@ -37,7 +48,7 @@ module RubyPlot
37
48
  end
38
49
 
39
50
  if status
40
- raise "Usage: svg_roc_plot (svg_path(?), title(string), x-lable(string), y-lable(sting), algorithms(array), true_pos_data1(array), false_pos_data1(array), ..., true_pos_data_n(array), false_pos_data_n(array))\n"+
51
+ raise "Usage: svg_roc_plot (path(?), title(string), x-lable(string), y-lable(sting), algorithms(array), true_pos_data1(array), false_pos_data1(array), ..., true_pos_data_n(array), false_pos_data_n(array))\n"+
41
52
  " Only pairs of data are allowed but at least one.\n"+
42
53
  " Each data array has to provide one float/int number from 0 to 100 per entry."
43
54
  end
@@ -102,20 +113,47 @@ module RubyPlot
102
113
  output_plt_arr = Array.new
103
114
  output_plt_arr.push "# Specifies encoding and output format"
104
115
  output_plt_arr.push "set encoding default"
105
- #output_plt_arr.push "set terminal svg"
106
- output_plt_arr.push 'set terminal svg size 800,600 dynamic enhanced fname "Arial" fsize 12 butt'
107
- output_plt_arr.push "set output '#{svg_path}'"
116
+
117
+ if path=~/(?i)svg/
118
+ output_plt_arr.push 'set terminal svg size 800,600 dynamic enhanced fname "Arial" fsize 12 butt'
119
+ elsif path=~/(?i)png/
120
+ output_plt_arr.push 'set terminal png'
121
+ else
122
+ raise "format not supported "+path.to_s
123
+ end
124
+ # x and y have equal scale
125
+ output_plt_arr.push 'set size ratio -1'
126
+
127
+ if log
128
+ output_plt_arr.push 'set logscale x'
129
+ output_plt_arr.push 'set logscale y'
130
+ end
131
+
132
+ output_plt_arr.push "set output '#{path}'"
108
133
  output_plt_arr.push ""
109
134
  output_plt_arr.push "# Specifies the range of the axes and appearance"
110
135
 
111
- #output_plt_arr.push "set xrange [0:100]"
112
- #output_plt_arr.push "set yrange [0:100]"
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+"]"
150
+
113
151
  output_plt_arr.push "set grid lw 0.5"
114
152
  output_plt_arr.push "set title \"#{title}\""
115
153
  output_plt_arr.push "set key below"
116
154
  output_plt_arr.push "set xlabel \"#{x_lable}\""
117
155
  output_plt_arr.push "set ylabel \"#{y_lable}\""
118
- #output_plt_arr.push "set arrow to 1,1 nohead"
156
+ #output_plt_arr.push "set arrow from "+min.to_s+","+min.to_s+" to "+max.to_s+","+max.to_s+" nohead"
119
157
  output_plt_arr.push ""
120
158
  output_plt_arr.push ""
121
159
  output_plt_arr.push ""
@@ -156,7 +194,7 @@ module RubyPlot
156
194
  end
157
195
  raise "gnuplot failes (cmd: "+cmd.to_s+", out: "+response.to_s+")" unless $?==0
158
196
 
159
- LOGGER.debug "#{svg_path} created. "
197
+ LOGGER.debug "#{path} created. "
160
198
 
161
199
  # -----------------------------------------------------
162
200
  # remove *.plt and *.dat files
@@ -170,7 +208,9 @@ module RubyPlot
170
208
  end
171
209
 
172
210
  def self.test_plot_points
173
- plot_points("/tmp/result.svg" , "name of title", "x-values", "y-values", ["this-one-has-a-very-very-very-long-name", "test" ], [[0.20,0.60,0.80], [0.10,0.25,0.70,0.95]], [[0.15,0.50,0.90],[0.20,0.40,0.50,0.70]])
211
+ plot_points("/tmp/result.png" , "name of title", "x-values", "y-values", ["this-one-has-a-very-very-very-long-name", "test" ],
212
+ [[0.20,0.60,0.80,0.20,1.0,0.001], [0.10,0.25,0.70,0.95,0.2,0.3434]],
213
+ [[0.15,0.50,0.90,0.2,9,0.5],[0.20,0.40,0.50,0.70,0.3,0.234589]])
174
214
  end
175
215
 
176
216
  private
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-plot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
5
11
  platform: ruby
6
12
  authors:
7
13
  - David Vorgrimmler
@@ -10,19 +16,23 @@ autorequire:
10
16
  bindir: bin
11
17
  cert_chain: []
12
18
 
13
- date: 2010-06-07 00:00:00 +02:00
19
+ date: 2011-05-12 00:00:00 +02:00
14
20
  default_executable:
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
23
  name: gnuplot
18
- type: :runtime
19
- version_requirement:
20
- version_requirements: !ruby/object:Gem::Requirement
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
21
27
  requirements:
22
28
  - - ">="
23
29
  - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
24
33
  version: "0"
25
- version:
34
+ type: :runtime
35
+ version_requirements: *id001
26
36
  description: ""
27
37
  email: vorgrimmlerdavid@gmx.de
28
38
  executables: []
@@ -44,26 +54,32 @@ homepage: http://github.com/davor/ruby-plot
44
54
  licenses: []
45
55
 
46
56
  post_install_message:
47
- rdoc_options:
48
- - --charset=UTF-8
57
+ rdoc_options: []
58
+
49
59
  require_paths:
50
60
  - lib
51
61
  required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
52
63
  requirements:
53
64
  - - ">="
54
65
  - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
55
69
  version: "0"
56
- version:
57
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
61
78
  version: "0"
62
- version:
63
79
  requirements: []
64
80
 
65
81
  rubyforge_project:
66
- rubygems_version: 1.3.5
82
+ rubygems_version: 1.5.2
67
83
  signing_key:
68
84
  specification_version: 3
69
85
  summary: gnuplot wrapper for ruby, especially for plotting roc curves into svg files