ruby-plot 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/plot_lines.rb +38 -55
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/lib/plot_lines.rb
CHANGED
@@ -7,40 +7,18 @@
|
|
7
7
|
# Usage: See below.
|
8
8
|
|
9
9
|
module RubyPlot
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
LOGGER.debug "plot lines -- "+y_values.inspect
|
16
|
-
LOGGER.debug "plot lines -- "+labels.inspect
|
17
|
-
|
18
|
-
data = []
|
19
|
-
(0..x_values.size-1).each do |i|
|
20
|
-
data << y_values[i]
|
21
|
-
data << x_values[i]
|
22
|
-
end
|
23
|
-
|
24
|
-
#Main
|
25
|
-
STDOUT.sync = true
|
26
|
-
# -----------------------------------------------------
|
27
|
-
# checking input
|
28
|
-
# -----------------------------------------------------
|
29
|
-
# check parameters
|
30
|
-
status=false
|
31
|
-
LOGGER.debug "#{names.length} algs entered"
|
32
|
-
|
33
|
-
#LOGGER.debug names.inspect
|
34
|
-
#LOGGER.debug data.inspect
|
35
|
-
|
36
|
-
if names.length != data.length/2
|
37
|
-
status=true
|
10
|
+
|
11
|
+
class LinePlotData
|
12
|
+
attr_accessor :name, :x_values, :y_values, :faint, :labels
|
13
|
+
def initialize(params)
|
14
|
+
params.each{|k,v| send((k.to_s+"=").to_sym,v)}
|
38
15
|
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.plot_lines(path, title, x_lable, y_lable, plot_data )
|
39
19
|
|
40
|
-
|
41
|
-
|
42
|
-
" Only pairs of data are allowed but at least one.\n"+
|
43
|
-
" Each data array has to provide one float/int number from 0 to 100 per entry."
|
20
|
+
plot_data.each do |d|
|
21
|
+
LOGGER.debug "plot lines -- "+d.name+" - "+d.x_values.inspect+" - "+d.y_values.inspect+" - "+d.labels.inspect
|
44
22
|
end
|
45
23
|
|
46
24
|
# gnuplot check
|
@@ -52,18 +30,18 @@ module RubyPlot
|
|
52
30
|
"sudo apt-get install gnuplot"
|
53
31
|
end
|
54
32
|
|
55
|
-
dat_number=0
|
56
|
-
|
57
33
|
output_dat_arr = Array.new
|
58
34
|
|
59
|
-
|
60
35
|
# -----------------------------------------------------
|
61
36
|
# create *.dat files of imported data for gnuplot
|
62
37
|
# -----------------------------------------------------
|
63
38
|
# write true/false arrays to one array
|
64
|
-
for i in 0..
|
65
|
-
|
66
|
-
|
39
|
+
#for i in 0..plot_data.length-1#/2-1
|
40
|
+
plot_data.size.times do |i|
|
41
|
+
|
42
|
+
true_pos_arr = plot_data[i].y_values
|
43
|
+
false_pos_arr = plot_data[i].x_values
|
44
|
+
|
67
45
|
#check length of input files
|
68
46
|
if true_pos_arr.length == false_pos_arr.length
|
69
47
|
#LOGGER.debug "Same length!"
|
@@ -73,11 +51,11 @@ module RubyPlot
|
|
73
51
|
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
|
74
52
|
output_dat_arr[j] = "#{true_pos_arr[j]} #{false_pos_arr[j]}"
|
75
53
|
else
|
76
|
-
raise "The data
|
54
|
+
raise "The data #{plot_data[i].inspect} has not the right formatin at position #{j}\n"+
|
77
55
|
"The right format is one float/int from 0 to 100 each line (e.g. '0'; '23,34'; '65.87' or '99')"
|
78
56
|
end
|
79
57
|
else
|
80
|
-
raise "The data
|
58
|
+
raise "The data #{plot_data[i].inspect} has not the right formatin at position #{j}+\n"
|
81
59
|
"The right format is one float/int from 0 to 100 each line (e.g. '0'; '23,34'; '65.87' or '99')"
|
82
60
|
end
|
83
61
|
end
|
@@ -92,7 +70,7 @@ module RubyPlot
|
|
92
70
|
output_dat_arr.clear
|
93
71
|
|
94
72
|
else
|
95
|
-
raise "
|
73
|
+
raise "num x-values != y-values: "+plot_data[i].inspect
|
96
74
|
end
|
97
75
|
end
|
98
76
|
|
@@ -133,33 +111,33 @@ module RubyPlot
|
|
133
111
|
output_plt_arr.push ""
|
134
112
|
output_plt_arr.push "# Draws the plot and specifies its appearance ..."
|
135
113
|
|
136
|
-
|
137
|
-
|
138
|
-
labels
|
139
|
-
|
114
|
+
type = 1
|
115
|
+
plot_data.each do |p|
|
116
|
+
if p.labels
|
117
|
+
p.labels.each do |label|
|
140
118
|
l = label[0]
|
141
119
|
x = label[1]
|
142
120
|
y = label[2]
|
143
|
-
puts l.to_s+" "+x.to_s+" "+y.to_s
|
121
|
+
#puts l.to_s+" "+x.to_s+" "+y.to_s
|
144
122
|
#output_plt_arr.push "set label \"("+x.to_s+","+y.to_s+") "+l.to_s+"\" at first 25, first 40"
|
145
123
|
output_plt_arr.push "set label \""+l.to_s+"\" at first "+x.to_s+", first "+y.to_s+" front offset 1,-1 tc lt "+type.to_s
|
146
124
|
output_plt_arr.push "set arrow from "+(x+3).to_s+","+(y-3).to_s+" to "+(x+1).to_s+","+(y-1).to_s+" lt "+type.to_s
|
147
125
|
end
|
148
|
-
|
149
|
-
|
126
|
+
end
|
127
|
+
type += 1
|
150
128
|
end
|
151
129
|
|
152
130
|
output_plt_arr.push "plot \\"#'random_0.dat' using 1:2 title 'random' with lines lw 1, \\"
|
153
131
|
i = 0
|
154
|
-
for i in 0..
|
132
|
+
for i in 0..plot_data.length-1
|
155
133
|
|
156
134
|
#style = grey[i] ? "lw 1.5 lt 0" : "lw 3"
|
157
|
-
style =
|
135
|
+
style = plot_data[i].faint ? "lw 2" : "lw 4"
|
158
136
|
|
159
|
-
if i ==
|
160
|
-
output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{
|
137
|
+
if i == plot_data.length-1
|
138
|
+
output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{plot_data[i].name}' with lines #{style}"
|
161
139
|
else
|
162
|
-
output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{
|
140
|
+
output_plt_arr.push " 'data#{i}.dat' using 2:1 title '#{plot_data[i].name}' with lines #{style}, \\"
|
163
141
|
end
|
164
142
|
end
|
165
143
|
output_plt_arr.push ""
|
@@ -191,7 +169,7 @@ module RubyPlot
|
|
191
169
|
# -----------------------------------------------------
|
192
170
|
`rm config.plt`
|
193
171
|
LOGGER.debug "config.plt removed."
|
194
|
-
for i in 0..
|
172
|
+
for i in 0..plot_data.length-1
|
195
173
|
`rm data#{i}.dat`
|
196
174
|
LOGGER.debug "data#{i}.dat removed."
|
197
175
|
end
|
@@ -199,8 +177,13 @@ module RubyPlot
|
|
199
177
|
|
200
178
|
def self.test_plot_lines
|
201
179
|
#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])
|
180
|
+
#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],[nil,["confidence",25,40]])
|
202
181
|
|
203
|
-
|
182
|
+
plot_data = []
|
183
|
+
plot_data << LinePlotData.new({ :name => "name", :x_values => [20,60,80], :y_values => [15,50,90] })
|
184
|
+
plot_data << LinePlotData.new({ :name => "test", :x_values => [10,25,70,95], :y_values => [20,40,50,70], :labels => [["confidence",25,40]] })
|
185
|
+
plot_data << LinePlotData.new({ :name => "bla", :x_values => [12,78,99], :y_values =>[34,89,89], :faint => true })
|
186
|
+
plot_lines("/tmp/result.png" , "name of title", "x-values", "y-values", plot_data)
|
204
187
|
end
|
205
188
|
|
206
189
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.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-
|
19
|
+
date: 2011-05-24 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|