ruby-plot 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +22 -0
- data/Rakefile +41 -0
- data/VERSION +1 -0
- data/lib/plot_bars.rb +63 -0
- data/lib/plot_lines.rb +183 -0
- data/lib/plot_points.rb +182 -0
- data/lib/ruby-plot.rb +16 -0
- metadata +71 -0
data/README
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
README
|
2
|
+
svg_roc_plot.rb
|
3
|
+
Copyright 2010 vorgrimmler <dv(a_t)fdm.uni-freiburg.de>
|
4
|
+
This ruby program exports inputs data(from true-positive-rate and false-positive-rate files) to a *.svg file using gnuplot. Depending on the amount of input data is possible to create 1 to n curves in one plot.
|
5
|
+
Gnuplot is needed. Please install befor using svg_roc_plot. "sudo apt-get install gnuplot" (on debian systems)
|
6
|
+
|
7
|
+
Usage: ruby svg_roc_plot.rb ([filename_1] [filename_2]) ... ([filename_1] [filenam_2])
|
8
|
+
cmd=filename_1 : This should be the filename of the ture-positiv-rate data.
|
9
|
+
cmd=filename_2 : This should be the filename of the false-positiv-rate data.
|
10
|
+
Only pairs of input files are allowed but at least one.
|
11
|
+
Each input file has to provide one float number from 0 to 100 per line.
|
12
|
+
|
13
|
+
|
14
|
+
svg_roc_plot_method.rb
|
15
|
+
Copyright 2010 vorgrimmler <dv(a_t)fdm.uni-freiburg.de>
|
16
|
+
This ruby method (svg_roc_plot) exports inputs data(from true-positive-rate and false-positive-rate arrays) to a *.svg file using gnuplot. Depending on the amount of input data is possible to create 1 to n curves in one plot.
|
17
|
+
Gnuplot is needed. Please install befor using svg_roc_plot. "sudo apt-get install gnuplot" (on debian systems).
|
18
|
+
|
19
|
+
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))
|
20
|
+
Only pairs of data are allowed but at least one.
|
21
|
+
Each data array has to provide one float/int number from 0 to 100 per entry.
|
22
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ruby-plot"
|
8
|
+
gem.summary = %Q{gnuplot wrapper for ruby, especially for plotting roc curves into svg files}
|
9
|
+
gem.description = %Q{}
|
10
|
+
gem.email = "vorgrimmlerdavid@gmx.de"
|
11
|
+
gem.homepage = "http://github.com/davor/ruby-plot"
|
12
|
+
gem.authors = ["David Vorgrimmler", "Martin Gütlein"]
|
13
|
+
['gnuplot'].each do |dep|
|
14
|
+
gem.add_dependency dep
|
15
|
+
end
|
16
|
+
gem.files = FileList["[A-Z]*", "{bin,generators,lib,test}/**/*"]
|
17
|
+
gem.files.include %w(lib/ruby-plot.rb)
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
task :test => :check_dependencies
|
26
|
+
|
27
|
+
task :default => :test
|
28
|
+
|
29
|
+
require 'rake/rdoctask'
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
if File.exist?('VERSION')
|
32
|
+
version = File.read('VERSION')
|
33
|
+
else
|
34
|
+
version = ""
|
35
|
+
end
|
36
|
+
|
37
|
+
rdoc.rdoc_dir = 'rdoc'
|
38
|
+
rdoc.title = "ruby-plot #{version}"
|
39
|
+
rdoc.rdoc_files.include('README*')
|
40
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
41
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
data/lib/plot_bars.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
module RubyPlot
|
3
|
+
|
4
|
+
def self.plot_bars(title = '', measures = [], algorithms = [], output_file = '')
|
5
|
+
|
6
|
+
#puts "'"+title+"',"+measures.inspect+","+algorithms.inspect+","
|
7
|
+
|
8
|
+
measures = measures.collect{|m| m.gsub(/_/,'-')}
|
9
|
+
|
10
|
+
Gnuplot.open do |gp|
|
11
|
+
Gnuplot::Plot.new( gp ) do |plot|
|
12
|
+
string = ''
|
13
|
+
(1..measures.length).collect.each do |i|
|
14
|
+
string += '"' + measures[i-1] + '" ' + i.to_s + ".00000 -1 "
|
15
|
+
end
|
16
|
+
|
17
|
+
plot.terminal 'svg size 800,600 dynamic enhanced fname "Arial" fsize 12 butt'
|
18
|
+
plot.output output_file
|
19
|
+
plot.bar '1.000000'
|
20
|
+
plot.boxwidth '0.9 absolute'
|
21
|
+
plot.style 'fill solid 1.00 border -1'
|
22
|
+
plot.style 'rectangle back fc lt -3 fillstyle solid 1.00 border -1'
|
23
|
+
#plot.key 'outside right top vertical Right noreverse enhanced autotitles columnhead nobox'
|
24
|
+
#plot.key "invert reverse Left outside"
|
25
|
+
plot.key "below"
|
26
|
+
|
27
|
+
plot.style 'histogram clustered gap 3 title offset character 0, 0, 0'
|
28
|
+
# plot.datafile 'missing "-"'
|
29
|
+
plot.style 'data histograms'
|
30
|
+
plot.xtics 'border in scale 1,0.5 nomirror offset character 0, 0, 0'
|
31
|
+
#plot.xtics 'norangelimit'
|
32
|
+
plot.xtics 'rotate'
|
33
|
+
#plot.xtics string
|
34
|
+
plot.title title
|
35
|
+
plot.rrange '[ * : * ] noreverse nowriteback # (currently [0.00000:10.0000])'
|
36
|
+
plot.trange '[ * : * ] noreverse nowriteback # (currently [-5.00000:5.00000])'
|
37
|
+
plot.urange '[ * : * ] noreverse nowriteback # (currently [-5.00000:5.00000])'
|
38
|
+
plot.vrange '[ * : * ] noreverse nowriteback # (currently [-5.00000:5.00000])'
|
39
|
+
# plot.ylabel 'offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90'
|
40
|
+
# plot.y2label 'offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90'
|
41
|
+
plot.yrange '[ 0.00000 : 1.00000 ] noreverse nowriteback' #
|
42
|
+
plot.cblabel 'offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90'
|
43
|
+
plot.locale '"C"'
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
algorithms.each do |algorithm|
|
48
|
+
plot.data << Gnuplot::DataSet.new([ ["A"].concat(measures), algorithm ]) do |ds|
|
49
|
+
ds.using = "2:xtic(1) ti col"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
LOGGER.info "plotted "+output_file.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.test_plot_bars
|
58
|
+
x = ['ACC_with_very_long_name_consider_that', 'AUC', 'SPEC', 'SENS']
|
59
|
+
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
|
+
plot_bars('Vergleich der Algorithmen', x, data, '/tmp/hist.svg')
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/lib/plot_lines.rb
ADDED
@@ -0,0 +1,183 @@
|
|
1
|
+
#!/usr/bin/ruby1.8
|
2
|
+
# svg_roc_plot method - svg_roc_plot_method.rb
|
3
|
+
#
|
4
|
+
# Copyright 2010 vorgrimmler <dv(a_t)fdm.uni-freiburg.de>
|
5
|
+
# This ruby method (svg_roc_plot) exports input data(from true-positive-rate and false-positive-rate arrays) to a *.svg file using gnuplot. Depending on the amount of input data is possible to create 1 to n curves in one plot.
|
6
|
+
# Gnuplot is needed. Please install befor using svg_roc_plot. "sudo apt-get install gnuplot" (on debian systems).
|
7
|
+
# Usage: See below.
|
8
|
+
|
9
|
+
module RubyPlot
|
10
|
+
|
11
|
+
def self.plot_lines(svg_path, title, x_lable, y_lable, names, x_values, y_values, faint=nil)
|
12
|
+
|
13
|
+
#LOGGER.debug names.inspect
|
14
|
+
#LOGGER.debug x_values.inspect
|
15
|
+
#LOGGER.debug y_values.inspect
|
16
|
+
|
17
|
+
data = []
|
18
|
+
(0..x_values.size-1).each do |i|
|
19
|
+
data << y_values[i]
|
20
|
+
data << x_values[i]
|
21
|
+
end
|
22
|
+
|
23
|
+
#Main
|
24
|
+
STDOUT.sync = true
|
25
|
+
# -----------------------------------------------------
|
26
|
+
# checking input
|
27
|
+
# -----------------------------------------------------
|
28
|
+
# check parameters
|
29
|
+
status=false
|
30
|
+
LOGGER.debug "#{names.length} algs entered"
|
31
|
+
|
32
|
+
#LOGGER.debug names.inspect
|
33
|
+
#LOGGER.debug data.inspect
|
34
|
+
|
35
|
+
if names.length != data.length/2
|
36
|
+
status=true
|
37
|
+
end
|
38
|
+
|
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"+
|
41
|
+
" Only pairs of data are allowed but at least one.\n"+
|
42
|
+
" Each data array has to provide one float/int number from 0 to 100 per entry."
|
43
|
+
end
|
44
|
+
|
45
|
+
# gnuplot check
|
46
|
+
gnuplot=`which gnuplot | grep -o gnuplot`
|
47
|
+
if gnuplot == "gnuplot\n"
|
48
|
+
LOGGER.debug "Gnuplot is already installed."
|
49
|
+
else
|
50
|
+
raise "Please install gnuplot.\n"+
|
51
|
+
"sudo apt-get install gnuplot"
|
52
|
+
end
|
53
|
+
|
54
|
+
dat_number=0
|
55
|
+
|
56
|
+
output_dat_arr = Array.new
|
57
|
+
|
58
|
+
|
59
|
+
# -----------------------------------------------------
|
60
|
+
# create *.dat files of imported data for gnuplot
|
61
|
+
# -----------------------------------------------------
|
62
|
+
# write true/false arrays to one array
|
63
|
+
for i in 0..names.length-1#/2-1
|
64
|
+
true_pos_arr = data[i*2]
|
65
|
+
false_pos_arr = data[i*2+1]
|
66
|
+
#check length of input files
|
67
|
+
if true_pos_arr.length == false_pos_arr.length
|
68
|
+
#LOGGER.debug "Same length!"
|
69
|
+
for j in 0..true_pos_arr.length-1
|
70
|
+
#check if array entries are float format and between 0.0 and 100.0
|
71
|
+
if numeric?(true_pos_arr[j].to_s.tr(',', '.')) && true_pos_arr[j].to_s.tr(',', '.').to_f <= 100 && true_pos_arr[j].to_s.tr(',', '.').to_f >= 0
|
72
|
+
if numeric?(false_pos_arr[j].to_s.tr(',', '.')) && false_pos_arr[j].to_s.tr(',', '.').to_f <= 100 && false_pos_arr[j].to_s.tr(',', '.').to_f >= 0
|
73
|
+
output_dat_arr[j] = "#{true_pos_arr[j]} #{false_pos_arr[j]}"
|
74
|
+
else
|
75
|
+
raise "The data of #{names[i]} has not the right formatin at position #{j}\n"+
|
76
|
+
"The right format is one float/int from 0 to 100 each line (e.g. '0'; '23,34'; '65.87' or '99')"
|
77
|
+
end
|
78
|
+
else
|
79
|
+
raise "The data of #{names[i]} has not the right formatin at position #{j}+\n"
|
80
|
+
"The right format is one float/int from 0 to 100 each line (e.g. '0'; '23,34'; '65.87' or '99')"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
#-----------------------------------------------------
|
84
|
+
#write *.dat files
|
85
|
+
#-----------------------------------------------------
|
86
|
+
#write output_dat_arr content in new *.dat file
|
87
|
+
File.open( "data#{i}.dat", "w" ) do |the_file|
|
88
|
+
the_file.puts output_dat_arr
|
89
|
+
end
|
90
|
+
LOGGER.debug "data#{i}.dat created."
|
91
|
+
output_dat_arr.clear
|
92
|
+
|
93
|
+
else
|
94
|
+
raise "Data pair of #{names[i]} have no the same number of elements."
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# -----------------------------------------------------
|
99
|
+
# create *.plt file for gnuplot
|
100
|
+
# -----------------------------------------------------
|
101
|
+
#
|
102
|
+
output_plt_arr = Array.new
|
103
|
+
output_plt_arr.push "# Specifies encoding and output format"
|
104
|
+
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}'"
|
108
|
+
output_plt_arr.push ""
|
109
|
+
output_plt_arr.push "# Specifies the range of the axes and appearance"
|
110
|
+
|
111
|
+
output_plt_arr.push "set xrange [0:100]"
|
112
|
+
output_plt_arr.push "set yrange [0:100]"
|
113
|
+
output_plt_arr.push "set grid lw 0.5"
|
114
|
+
output_plt_arr.push "set title \"#{title}\""
|
115
|
+
output_plt_arr.push "set key below"
|
116
|
+
#output_plt_arr.push "set key invert reverse Left outside"
|
117
|
+
output_plt_arr.push "set xlabel \"#{x_lable}\""
|
118
|
+
output_plt_arr.push "set ylabel \"#{y_lable}\""
|
119
|
+
output_plt_arr.push "set arrow from 0,0 to 100,100 nohead"
|
120
|
+
output_plt_arr.push ""
|
121
|
+
output_plt_arr.push ""
|
122
|
+
output_plt_arr.push ""
|
123
|
+
output_plt_arr.push ""
|
124
|
+
output_plt_arr.push "# Draws the plot and specifies its appearance ..."
|
125
|
+
output_plt_arr.push "plot \\"#'random_0.dat' using 1:2 title 'random' with lines lw 1, \\"
|
126
|
+
i = 0
|
127
|
+
for i in 0..names.length-1
|
128
|
+
|
129
|
+
#style = grey[i] ? "lw 1.5 lt 0" : "lw 3"
|
130
|
+
style = faint!=nil && faint[i] ? "lw 2" : "lw 4"
|
131
|
+
|
132
|
+
if i == names.length-1
|
133
|
+
output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{names[i]}' with lines #{style}"
|
134
|
+
else
|
135
|
+
output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{names[i]}' with lines #{style}, \\"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
output_plt_arr.push ""
|
139
|
+
output_plt_arr.push ""
|
140
|
+
|
141
|
+
# -----------------------------------------------------
|
142
|
+
# write *.plt files
|
143
|
+
# -----------------------------------------------------
|
144
|
+
# write output_dat_arr content in new *.dat file
|
145
|
+
File.open( "config.plt", "w" ) do |the_file|
|
146
|
+
the_file.puts output_plt_arr
|
147
|
+
end
|
148
|
+
LOGGER.debug "config.plt created, running gnuplot"
|
149
|
+
|
150
|
+
# start gnuplot with created *.plt file
|
151
|
+
cmd = "gnuplot config.plt 2>&1"
|
152
|
+
response = ""
|
153
|
+
IO.popen(cmd) do |f|
|
154
|
+
while line = f.gets
|
155
|
+
response += line
|
156
|
+
end
|
157
|
+
end
|
158
|
+
raise "gnuplot failes (cmd: "+cmd.to_s+", out: "+response.to_s+")" unless $?==0
|
159
|
+
|
160
|
+
LOGGER.debug "#{svg_path} created. "
|
161
|
+
|
162
|
+
# -----------------------------------------------------
|
163
|
+
# remove *.plt and *.dat files
|
164
|
+
# -----------------------------------------------------
|
165
|
+
`rm config.plt`
|
166
|
+
LOGGER.debug "config.plt removed."
|
167
|
+
for i in 0..names.length-1
|
168
|
+
`rm data#{i}.dat`
|
169
|
+
LOGGER.debug "data#{i}.dat removed."
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def self.test_plot_lines
|
174
|
+
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])
|
175
|
+
end
|
176
|
+
|
177
|
+
private
|
178
|
+
# float check
|
179
|
+
def self.numeric?(object)
|
180
|
+
true if Float(object) rescue false
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
data/lib/plot_points.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
#!/usr/bin/ruby1.8
|
2
|
+
# svg_roc_plot method - svg_roc_plot_method.rb
|
3
|
+
#
|
4
|
+
# Copyright 2010 vorgrimmler <dv(a_t)fdm.uni-freiburg.de>
|
5
|
+
# This ruby method (svg_roc_plot) exports input data(from true-positive-rate and false-positive-rate arrays) to a *.svg file using gnuplot. Depending on the amount of input data is possible to create 1 to n curves in one plot.
|
6
|
+
# Gnuplot is needed. Please install befor using svg_roc_plot. "sudo apt-get install gnuplot" (on debian systems).
|
7
|
+
# Usage: See below.
|
8
|
+
|
9
|
+
module RubyPlot
|
10
|
+
|
11
|
+
def self.plot_points(svg_path, title, x_lable, y_lable, names, x_values, y_values)
|
12
|
+
|
13
|
+
LOGGER.debug names.inspect
|
14
|
+
LOGGER.debug x_values.inspect
|
15
|
+
LOGGER.debug y_values.inspect
|
16
|
+
|
17
|
+
data = []
|
18
|
+
(0..x_values.size-1).each do |i|
|
19
|
+
data << y_values[i]
|
20
|
+
data << x_values[i]
|
21
|
+
end
|
22
|
+
|
23
|
+
#Main
|
24
|
+
STDOUT.sync = true
|
25
|
+
# -----------------------------------------------------
|
26
|
+
# checking input
|
27
|
+
# -----------------------------------------------------
|
28
|
+
# check parameters
|
29
|
+
status=false
|
30
|
+
LOGGER.debug "#{names.length} algs entered"
|
31
|
+
|
32
|
+
#LOGGER.debug names.inspect
|
33
|
+
#LOGGER.debug data.inspect
|
34
|
+
|
35
|
+
if names.length != data.length/2
|
36
|
+
status=true
|
37
|
+
end
|
38
|
+
|
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"+
|
41
|
+
" Only pairs of data are allowed but at least one.\n"+
|
42
|
+
" Each data array has to provide one float/int number from 0 to 100 per entry."
|
43
|
+
end
|
44
|
+
|
45
|
+
# gnuplot check
|
46
|
+
gnuplot=`which gnuplot | grep -o gnuplot`
|
47
|
+
if gnuplot == "gnuplot\n"
|
48
|
+
LOGGER.debug "Gnuplot is already installed."
|
49
|
+
else
|
50
|
+
raise "Please install gnuplot.\n"+
|
51
|
+
"sudo apt-get install gnuplot"
|
52
|
+
end
|
53
|
+
|
54
|
+
dat_number=0
|
55
|
+
|
56
|
+
output_dat_arr = Array.new
|
57
|
+
|
58
|
+
|
59
|
+
# -----------------------------------------------------
|
60
|
+
# create *.dat files of imported data for gnuplot
|
61
|
+
# -----------------------------------------------------
|
62
|
+
# write true/false arrays to one array
|
63
|
+
for i in 0..names.length-1#/2-1
|
64
|
+
true_pos_arr = data[i*2]
|
65
|
+
false_pos_arr = data[i*2+1]
|
66
|
+
#check length of input files
|
67
|
+
if true_pos_arr.length == false_pos_arr.length
|
68
|
+
#LOGGER.debug "Same length!"
|
69
|
+
for j in 0..true_pos_arr.length-1
|
70
|
+
#check if array entries are float format and between 0.0 and 100.0
|
71
|
+
#if numeric?(true_pos_arr[j].to_s.tr(',', '.')) && true_pos_arr[j].to_s.tr(',', '.').to_f <= 100 && true_pos_arr[j].to_s.tr(',', '.').to_f >= 0
|
72
|
+
# if numeric?(false_pos_arr[j].to_s.tr(',', '.')) && false_pos_arr[j].to_s.tr(',', '.').to_f <= 100 && false_pos_arr[j].to_s.tr(',', '.').to_f >= 0
|
73
|
+
output_dat_arr[j] = "#{true_pos_arr[j]} #{false_pos_arr[j]}"
|
74
|
+
# else
|
75
|
+
# raise "The data of #{names[i]} has not the right formatin at position #{j}\n"+
|
76
|
+
# "The right format is one float/int from 0 to 100 each line (e.g. '0'; '23,34'; '65.87' or '99')"
|
77
|
+
# end
|
78
|
+
#else
|
79
|
+
# raise "The data of #{names[i]} has not the right formatin at position #{j}+\n"
|
80
|
+
# "The right format is one float/int from 0 to 100 each line (e.g. '0'; '23,34'; '65.87' or '99')"
|
81
|
+
#end
|
82
|
+
end
|
83
|
+
#-----------------------------------------------------
|
84
|
+
#write *.dat files
|
85
|
+
#-----------------------------------------------------
|
86
|
+
#write output_dat_arr content in new *.dat file
|
87
|
+
File.open( "data#{i}.dat", "w" ) do |the_file|
|
88
|
+
the_file.puts output_dat_arr
|
89
|
+
end
|
90
|
+
LOGGER.debug "data#{i}.dat created."
|
91
|
+
output_dat_arr.clear
|
92
|
+
|
93
|
+
else
|
94
|
+
raise "Data pair of #{names[i]} have no the same number of elements."
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# -----------------------------------------------------
|
99
|
+
# create *.plt file for gnuplot
|
100
|
+
# -----------------------------------------------------
|
101
|
+
#
|
102
|
+
output_plt_arr = Array.new
|
103
|
+
output_plt_arr.push "# Specifies encoding and output format"
|
104
|
+
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}'"
|
108
|
+
output_plt_arr.push ""
|
109
|
+
output_plt_arr.push "# Specifies the range of the axes and appearance"
|
110
|
+
|
111
|
+
#output_plt_arr.push "set xrange [0:100]"
|
112
|
+
#output_plt_arr.push "set yrange [0:100]"
|
113
|
+
output_plt_arr.push "set grid lw 0.5"
|
114
|
+
output_plt_arr.push "set title \"#{title}\""
|
115
|
+
output_plt_arr.push "set key below"
|
116
|
+
output_plt_arr.push "set xlabel \"#{x_lable}\""
|
117
|
+
output_plt_arr.push "set ylabel \"#{y_lable}\""
|
118
|
+
#output_plt_arr.push "set arrow to 1,1 nohead"
|
119
|
+
output_plt_arr.push ""
|
120
|
+
output_plt_arr.push ""
|
121
|
+
output_plt_arr.push ""
|
122
|
+
output_plt_arr.push ""
|
123
|
+
output_plt_arr.push "# Draws the plot and specifies its appearance ..."
|
124
|
+
|
125
|
+
output_plt_arr.push "plot \\"#'random_0.dat' using 1:2 title 'random' with lines lw 1, \\"
|
126
|
+
i = 0
|
127
|
+
for i in 0..names.length-1
|
128
|
+
if i == names.length-1
|
129
|
+
output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{names[i]}' with points"
|
130
|
+
else
|
131
|
+
output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{names[i]}' with points, \\"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
output_plt_arr.push ""
|
135
|
+
output_plt_arr.push ""
|
136
|
+
|
137
|
+
|
138
|
+
#output_plt_arr << "plot f(x)"
|
139
|
+
|
140
|
+
# -----------------------------------------------------
|
141
|
+
# write *.plt files
|
142
|
+
# -----------------------------------------------------
|
143
|
+
# write output_dat_arr content in new *.dat file
|
144
|
+
File.open( "config.plt", "w" ) do |the_file|
|
145
|
+
the_file.puts output_plt_arr
|
146
|
+
end
|
147
|
+
LOGGER.debug "config.plt created, running gnuplot"
|
148
|
+
|
149
|
+
# start gnuplot with created *.plt file
|
150
|
+
cmd = "gnuplot config.plt 2>&1"
|
151
|
+
response = ""
|
152
|
+
IO.popen(cmd) do |f|
|
153
|
+
while line = f.gets
|
154
|
+
response += line
|
155
|
+
end
|
156
|
+
end
|
157
|
+
raise "gnuplot failes (cmd: "+cmd.to_s+", out: "+response.to_s+")" unless $?==0
|
158
|
+
|
159
|
+
LOGGER.debug "#{svg_path} created. "
|
160
|
+
|
161
|
+
# -----------------------------------------------------
|
162
|
+
# remove *.plt and *.dat files
|
163
|
+
# -----------------------------------------------------
|
164
|
+
`rm config.plt`
|
165
|
+
LOGGER.debug "config.plt removed."
|
166
|
+
for i in 0..names.length-1
|
167
|
+
`rm data#{i}.dat`
|
168
|
+
LOGGER.debug "data#{i}.dat removed."
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
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]])
|
174
|
+
end
|
175
|
+
|
176
|
+
private
|
177
|
+
# float check
|
178
|
+
def self.numeric?(object)
|
179
|
+
true if Float(object) rescue false
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
data/lib/ruby-plot.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'logger'
|
3
|
+
require 'gnuplot'
|
4
|
+
|
5
|
+
unless(defined? LOGGER)
|
6
|
+
LOGGER = Logger.new(STDOUT)
|
7
|
+
LOGGER.datetime_format = "%Y-%m-%d %H:%M:%S "
|
8
|
+
end
|
9
|
+
|
10
|
+
require "plot_bars.rb"
|
11
|
+
require "plot_lines.rb"
|
12
|
+
require "plot_points.rb"
|
13
|
+
|
14
|
+
#RubyPlot::test_plot_lines
|
15
|
+
#RubyPlot::test_plot_bars
|
16
|
+
#RubyPlot::test_plot_points
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-plot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Vorgrimmler
|
8
|
+
- "Martin G\xC3\xBCtlein"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-06-07 00:00:00 +02:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: gnuplot
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
version:
|
26
|
+
description: ""
|
27
|
+
email: vorgrimmlerdavid@gmx.de
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files:
|
33
|
+
- README
|
34
|
+
files:
|
35
|
+
- README
|
36
|
+
- Rakefile
|
37
|
+
- VERSION
|
38
|
+
- lib/plot_bars.rb
|
39
|
+
- lib/plot_lines.rb
|
40
|
+
- lib/plot_points.rb
|
41
|
+
- lib/ruby-plot.rb
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/davor/ruby-plot
|
44
|
+
licenses: []
|
45
|
+
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options:
|
48
|
+
- --charset=UTF-8
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
version:
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.5
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: gnuplot wrapper for ruby, especially for plotting roc curves into svg files
|
70
|
+
test_files: []
|
71
|
+
|