numo-gnuplot 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -4
- data/examples/Rakefile +3 -0
- data/examples/all.rb +1 -1
- data/examples/ex011.rb +6 -6
- data/lib/numo/gnuplot.rb +273 -87
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8bcac7c2ba2e8b6312acd20b52748afd86ddeb2
|
4
|
+
data.tar.gz: c246dfd861b0a58a83a0b3a41f5868de6b4b4c29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16c972884c66c7ea7e85714ea53eb2482f4907eeed485d6287c1f251c06dd4031adf7bfc76d10ff059d8242ef15d63ad961e9d66c140d996b3cdb85c8e4e8080
|
7
|
+
data.tar.gz: a9408c167e56b22303cc77bb9b363be2b672f09031ea5465077918c8a40f3607f7153c02db739b390aad61ad62cf76888b20a98a0a98b9e831d06c886a0ab673
|
data/README.md
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
* [RubyGems site](https://rubygems.org/gems/numo-gnuplot)
|
6
6
|
* [API doc](http://www.rubydoc.info/gems/numo-gnuplot/Numo/Gnuplot)
|
7
7
|
|
8
|
+
* Visit [Demo page](https://github.com/ruby-numo/numo-gnuplot-demo).
|
9
|
+
|
8
10
|
Although there are many [other Gnuplot interface libraries for Ruby](https://github.com/ruby-numo/gnuplot#related-work),
|
9
11
|
none of them have so simple interface as to show an XY data plot by just typing:
|
10
12
|
|
@@ -178,6 +180,7 @@ Numo::Gnuplot class methods succeeded from Gnuplot commands:
|
|
178
180
|
|
179
181
|
* clear
|
180
182
|
* exit
|
183
|
+
* fit(*args)
|
181
184
|
* help(topic)
|
182
185
|
* load(filename)
|
183
186
|
* pause(*args)
|
@@ -190,6 +193,7 @@ Numo::Gnuplot class methods succeeded from Gnuplot commands:
|
|
190
193
|
* show(option)
|
191
194
|
* splot(*args)
|
192
195
|
* unset(*options)
|
196
|
+
* update(*files)
|
193
197
|
|
194
198
|
Numo::Gnuplot class methods renamed from Gnuplot commands:
|
195
199
|
|
@@ -198,11 +202,13 @@ Numo::Gnuplot class methods renamed from Gnuplot commands:
|
|
198
202
|
|
199
203
|
Numo::Gnuplot-specific methods:
|
200
204
|
|
201
|
-
* debug_off -- turn off debug print
|
202
|
-
* debug_on -- turn on debug print
|
203
|
-
*
|
205
|
+
* debug_off -- turn off debug print.
|
206
|
+
* debug_on -- turn on debug print.
|
207
|
+
* run(command_line) -- send command-line string to Gnuplot directly.
|
208
|
+
* output(filename,[term,*opts]) -- output current plot to file. If term is omitted, an extension in filename is regarded as a term name. This invokes the next commands;
|
204
209
|
```ruby
|
205
|
-
set terminal:[
|
210
|
+
set terminal:[term,*opts]
|
211
|
+
set output:filename; refresh
|
206
212
|
```
|
207
213
|
* var(name) -- returns variable content in the Gnuplot context.
|
208
214
|
|
data/examples/Rakefile
ADDED
data/examples/all.rb
CHANGED
data/examples/ex011.rb
CHANGED
@@ -12,11 +12,11 @@ x += df.zeros(n,1)
|
|
12
12
|
y += df.zeros(1,n)
|
13
13
|
|
14
14
|
Numo.gnuplot do
|
15
|
-
set title:'3D plot of XYZ data'
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
set title:'3D plot of XYZ data'
|
16
|
+
set palette:{rgbformula:[22,13,-31]}
|
17
|
+
set dgrid3d:[60,60]
|
18
|
+
set xlabel:'x'
|
19
|
+
set ylabel:'y'
|
20
|
+
set zlabel:'sin(r)/r'
|
21
21
|
splot x,y,z, w:'pm3d', t:'sin(r)/r'
|
22
22
|
end
|
data/lib/numo/gnuplot.rb
CHANGED
@@ -14,19 +14,20 @@ module Numo
|
|
14
14
|
end
|
15
15
|
module_function :noteplot
|
16
16
|
|
17
|
+
class GnuplotError < StandardError; end
|
18
|
+
|
17
19
|
class Gnuplot
|
18
20
|
|
19
|
-
VERSION = "0.
|
21
|
+
VERSION = "0.2.0"
|
20
22
|
POOL = []
|
21
23
|
DATA_FORMAT = "%.7g"
|
22
24
|
|
23
|
-
class GnuplotError < StandardError; end
|
24
|
-
|
25
25
|
def self.default
|
26
26
|
POOL[0] ||= self.new
|
27
27
|
end
|
28
28
|
|
29
29
|
class NotePlot
|
30
|
+
|
30
31
|
def initialize(&block)
|
31
32
|
if block.nil?
|
32
33
|
raise ArgumentError,"block is needed"
|
@@ -40,7 +41,8 @@ class Gnuplot
|
|
40
41
|
# output SVG to tmpfile
|
41
42
|
gp = Gnuplot.default
|
42
43
|
gp.reset
|
43
|
-
gp.set terminal:'svg'
|
44
|
+
gp.set terminal:'svg'
|
45
|
+
gp.output:tempfile_svg.path
|
44
46
|
gp.instance_eval(&@block)
|
45
47
|
gp.unset 'output'
|
46
48
|
svg = File.read(tempfile_svg.path)
|
@@ -73,19 +75,20 @@ class Gnuplot
|
|
73
75
|
|
74
76
|
# draw 2D functions and data.
|
75
77
|
def plot(*args)
|
76
|
-
|
78
|
+
contents = parse_plot_args(PlotItem,args)
|
79
|
+
_plot_splot("plot",contents)
|
77
80
|
nil
|
78
81
|
end
|
79
82
|
|
80
83
|
# draws 2D projections of 3D surfaces and data.
|
81
84
|
def splot(*args)
|
82
|
-
|
85
|
+
contents = parse_plot_args(SPlotItem,args)
|
86
|
+
_plot_splot("splot",contents)
|
83
87
|
nil
|
84
88
|
end
|
85
89
|
|
86
|
-
def _plot_splot(cmd,
|
87
|
-
|
88
|
-
r = contents.shift.map{|x|"[#{x.begin}:#{x.end}] "}.join
|
90
|
+
def _plot_splot(cmd,contents)
|
91
|
+
r = contents.shift.map{|x| "#{x} "}.join
|
89
92
|
c = contents.map{|x| x.cmd_str}.join(",")
|
90
93
|
d = contents.map{|x| x.data_str}.join
|
91
94
|
run "#{cmd} #{r}#{c}", d
|
@@ -94,37 +97,49 @@ class Gnuplot
|
|
94
97
|
private :_plot_splot
|
95
98
|
|
96
99
|
# replot is not recommended, use refresh
|
97
|
-
def replot
|
98
|
-
run "replot\n#{@last_data}"
|
100
|
+
def replot(arg=nil)
|
101
|
+
run "replot #{arg}\n#{@last_data}"
|
102
|
+
nil
|
103
|
+
end
|
104
|
+
|
105
|
+
# The `fit` command can fit a user-supplied expression to a set of
|
106
|
+
# data points (x,z) or (x,y,z), using an implementation of the
|
107
|
+
# nonlinear least-squares (NLLS) Marquardt-Levenberg algorithm.
|
108
|
+
def fit(*args)
|
109
|
+
range, items = parse_fit_args(args)
|
110
|
+
r = range.map{|x| "#{x} "}.join
|
111
|
+
c = items.cmd_str
|
112
|
+
puts send_cmd("fit #{r}#{c}")
|
99
113
|
nil
|
100
114
|
end
|
101
115
|
|
116
|
+
# This command writes the current values of the fit parameters into
|
117
|
+
# the given file, formatted as an initial-value file (as described
|
118
|
+
# in the `fit`section). This is useful for saving the current
|
119
|
+
# values for later use or for restarting a converged or stopped fit.
|
120
|
+
def update(*filenames)
|
121
|
+
puts send_cmd("update "+filenames.map{|f| OptArg.squote(f)}.join(" "))
|
122
|
+
end
|
123
|
+
|
124
|
+
# This command prepares a statistical summary of the data in one or
|
125
|
+
# two columns of a file.
|
126
|
+
def stats(filename,*args)
|
127
|
+
fn = OptArg.squote(filename)
|
128
|
+
opt = OptArg.parse(*args)
|
129
|
+
puts send_cmd "stats #{fn} #{opt}"
|
130
|
+
end
|
131
|
+
|
102
132
|
# The `set` command is used to set _lots_ of options.
|
103
133
|
def set(*args)
|
104
|
-
|
134
|
+
run "set #{OptArg.parse(*args)}"
|
105
135
|
nil
|
106
136
|
end
|
107
137
|
|
108
138
|
# The `unset` command is used to return to their default state.
|
109
139
|
def unset(*args)
|
110
|
-
|
111
|
-
nil
|
112
|
-
end
|
113
|
-
|
114
|
-
def _set_unset(cmd,args)
|
115
|
-
args.each do |a|
|
116
|
-
case a
|
117
|
-
when Hash
|
118
|
-
a.each do |k,v|
|
119
|
-
run "#{cmd} #{OptArg.parse_kv(k,v)}"
|
120
|
-
end
|
121
|
-
else
|
122
|
-
run "#{cmd} #{a}"
|
123
|
-
end
|
124
|
-
end
|
140
|
+
run "unset #{OptArg.parse(*args)}"
|
125
141
|
nil
|
126
142
|
end
|
127
|
-
private :_set_unset
|
128
143
|
|
129
144
|
# The `help` command displays built-in help.
|
130
145
|
def help(s=nil)
|
@@ -132,8 +147,8 @@ class Gnuplot
|
|
132
147
|
end
|
133
148
|
|
134
149
|
# The `show` command shows their settings.
|
135
|
-
def show(
|
136
|
-
puts send_cmd "show #{
|
150
|
+
def show(*args)
|
151
|
+
puts send_cmd "show #{OptArg.parse(*args)}"
|
137
152
|
end
|
138
153
|
|
139
154
|
# The `reset` command causes all graph-related options that can be
|
@@ -156,7 +171,7 @@ class Gnuplot
|
|
156
171
|
|
157
172
|
# The `load` command executes each line of the specified input file.
|
158
173
|
def load(filename)
|
159
|
-
|
174
|
+
run "load #{OptArg.squote(filename)}"
|
160
175
|
nil
|
161
176
|
end
|
162
177
|
|
@@ -215,16 +230,19 @@ class Gnuplot
|
|
215
230
|
|
216
231
|
# output current plot to file with terminal setting from extension
|
217
232
|
# (not Gnuplot command)
|
218
|
-
def output(filename,*opts)
|
219
|
-
if /\.(\w+)$/ =~ filename
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
unset :terminal, :output
|
225
|
-
else
|
233
|
+
def output(filename,term=nil,*opts)
|
234
|
+
if term.nil? && /\.(\w+)$/ =~ filename
|
235
|
+
term = $1
|
236
|
+
end
|
237
|
+
term = KNOWN_EXT[term] || term
|
238
|
+
if term.nil?
|
226
239
|
kernel_raise GnuplotError,"file extension is not given"
|
227
240
|
end
|
241
|
+
set terminal:[term,*opts]
|
242
|
+
set output:filename
|
243
|
+
refresh
|
244
|
+
unset :terminal
|
245
|
+
unset :output
|
228
246
|
end
|
229
247
|
|
230
248
|
|
@@ -238,13 +256,17 @@ class Gnuplot
|
|
238
256
|
@debug = false
|
239
257
|
end
|
240
258
|
|
259
|
+
# send command-line string to Gnuplot directly
|
260
|
+
def send(cmd)
|
261
|
+
puts send_cmd(cmd)
|
262
|
+
end
|
263
|
+
|
241
264
|
#other_commands = %w[
|
242
265
|
# bind
|
243
266
|
# call
|
244
267
|
# cd
|
245
268
|
# do
|
246
269
|
# evaluate
|
247
|
-
# fit
|
248
270
|
# history
|
249
271
|
# if
|
250
272
|
# print
|
@@ -252,10 +274,8 @@ class Gnuplot
|
|
252
274
|
# reread
|
253
275
|
# save
|
254
276
|
# shell
|
255
|
-
# stats
|
256
277
|
# system
|
257
278
|
# test
|
258
|
-
# update
|
259
279
|
# while
|
260
280
|
#]
|
261
281
|
|
@@ -269,16 +289,20 @@ class Gnuplot
|
|
269
289
|
def run(s,data=nil)
|
270
290
|
res = send_cmd(s,data)
|
271
291
|
if !res.empty?
|
272
|
-
if res.size
|
273
|
-
|
292
|
+
if res.size < 7
|
293
|
+
if res.all?{|x| /^\s*(line \d+: )?warning:/i =~ x}
|
294
|
+
$stderr.puts res.join.strip
|
295
|
+
return nil
|
296
|
+
else
|
297
|
+
msg = "\n"+res.join.strip
|
298
|
+
end
|
274
299
|
else
|
275
|
-
msg = "\n"+res.join
|
300
|
+
msg = "\n"+res[0..5].join.strip+"\n :\n"
|
276
301
|
end
|
277
302
|
kernel_raise GnuplotError,msg
|
278
303
|
end
|
279
304
|
nil
|
280
305
|
end
|
281
|
-
private :run
|
282
306
|
|
283
307
|
def send_cmd(s,data=nil)
|
284
308
|
puts "<"+s if @debug
|
@@ -290,25 +314,39 @@ class Gnuplot
|
|
290
314
|
@history << s
|
291
315
|
@last_message = []
|
292
316
|
while line=@ior.gets
|
293
|
-
puts ">"+line if @debug
|
294
317
|
break if /^_end_of_cmd_$/ =~ line
|
318
|
+
puts ">"+line if @debug
|
295
319
|
@last_message << line
|
296
320
|
end
|
297
321
|
@last_message
|
298
322
|
end
|
299
323
|
private :send_cmd
|
300
324
|
|
301
|
-
def parse_plot_args(
|
302
|
-
|
303
|
-
|
304
|
-
|
325
|
+
def parse_plot_args(cPlotItem,args)
|
326
|
+
range = []
|
327
|
+
while !args.empty?
|
328
|
+
case a = args.first
|
329
|
+
when Range
|
330
|
+
range << range_to_s(args.shift)
|
331
|
+
when String
|
332
|
+
if /^\[.*\]$/ =~ a
|
333
|
+
range << args.shift
|
334
|
+
else
|
335
|
+
break
|
336
|
+
end
|
337
|
+
else
|
338
|
+
break
|
339
|
+
end
|
340
|
+
end
|
341
|
+
item = cPlotItem.new # first item is range
|
342
|
+
list = [range,item]
|
305
343
|
args.each do |arg|
|
306
344
|
case arg
|
307
345
|
when Range
|
308
|
-
list.first << arg
|
346
|
+
list.first << range_to_s(arg)
|
309
347
|
when Array
|
310
348
|
if arg.all?{|e| e.kind_of?(Range)}
|
311
|
-
list.first
|
349
|
+
arg.each{|e| list.first << range_to_s(e)}
|
312
350
|
elsif PlotItem.is_data(arg)
|
313
351
|
item << arg
|
314
352
|
else
|
@@ -318,6 +356,9 @@ class Gnuplot
|
|
318
356
|
when Hash
|
319
357
|
item << arg
|
320
358
|
list << item = cPlotItem.new # next PlotItem
|
359
|
+
when String
|
360
|
+
list.pop if list.last.empty?
|
361
|
+
list << item = cPlotItem.new(arg) # next PlotItem
|
321
362
|
else
|
322
363
|
item << arg
|
323
364
|
end
|
@@ -327,27 +368,102 @@ class Gnuplot
|
|
327
368
|
end
|
328
369
|
private :parse_plot_args
|
329
370
|
|
371
|
+
def range_to_s(*a)
|
372
|
+
case a.size
|
373
|
+
when 1
|
374
|
+
a = a[0]
|
375
|
+
"[#{a.first}:#{a.last}]"
|
376
|
+
when 2
|
377
|
+
"[#{a[0]}:#{a[1]}]"
|
378
|
+
else
|
379
|
+
raise ArgumetError,"wrong number of argument"
|
380
|
+
end
|
381
|
+
end
|
382
|
+
private :range_to_s
|
383
|
+
|
384
|
+
def parse_fit_args(args)
|
385
|
+
range = []
|
386
|
+
while !args.empty?
|
387
|
+
case a = args.first
|
388
|
+
when Range
|
389
|
+
range << range_to_s(args.shift)
|
390
|
+
when String
|
391
|
+
if /^\[.*\]$/ =~ a
|
392
|
+
range << args.shift
|
393
|
+
else
|
394
|
+
break
|
395
|
+
end
|
396
|
+
else
|
397
|
+
break
|
398
|
+
end
|
399
|
+
end
|
400
|
+
items = FitItem.new(args.shift, args.shift)
|
401
|
+
args.each do |arg|
|
402
|
+
case arg
|
403
|
+
when Range
|
404
|
+
range << range_to_s(arg)
|
405
|
+
when Array
|
406
|
+
if arg.all?{|e| e.kind_of?(Range)}
|
407
|
+
arg.each{|e| range << range_to_s(e)}
|
408
|
+
else
|
409
|
+
items << arg
|
410
|
+
end
|
411
|
+
else
|
412
|
+
items << arg
|
413
|
+
end
|
414
|
+
end
|
415
|
+
return [range,items]
|
416
|
+
end
|
417
|
+
private :parse_fit_args
|
418
|
+
|
330
419
|
|
331
420
|
# @private
|
332
421
|
module OptArg # :nodoc: all
|
333
422
|
|
334
423
|
module_function
|
335
424
|
|
425
|
+
def from_symbol(s)
|
426
|
+
s = s.to_s
|
427
|
+
if /^(.*)_(noquote|nq)$/ =~ s
|
428
|
+
s = $1
|
429
|
+
end
|
430
|
+
s.tr('_',' ')
|
431
|
+
end
|
432
|
+
|
336
433
|
def parse(*opts)
|
337
434
|
sep = ","
|
338
|
-
|
339
|
-
|
435
|
+
a = []
|
436
|
+
while opt = opts.shift
|
437
|
+
if !opt.kind_of?(Numeric)
|
438
|
+
sep = " "
|
439
|
+
end
|
340
440
|
case opt
|
441
|
+
when Symbol
|
442
|
+
a << from_symbol(opt)
|
443
|
+
case opt
|
444
|
+
when :label
|
445
|
+
if opts.first.kind_of?(Integer)
|
446
|
+
a << opts.shift.to_s
|
447
|
+
end
|
448
|
+
if opts.first.kind_of?(String)
|
449
|
+
a << OptArg.quote(opts.shift)
|
450
|
+
end
|
451
|
+
when NEED_QUOTE
|
452
|
+
if opts.first.kind_of?(String)
|
453
|
+
a << OptArg.quote(opts.shift)
|
454
|
+
end
|
455
|
+
end
|
341
456
|
when Array
|
342
|
-
|
457
|
+
a << parse(*opt)
|
343
458
|
when Hash
|
344
|
-
opt.map{|k,v| parse_kv(k,v)}.compact.join(" ")
|
459
|
+
a << opt.map{|k,v| parse_kv(k,v)}.compact.join(" ")
|
345
460
|
when Range
|
346
|
-
"[#{opt.begin}:#{opt.end}]"
|
461
|
+
a << "[#{opt.begin}:#{opt.end}]"
|
347
462
|
else
|
348
|
-
opt.to_s
|
463
|
+
a << opt.to_s
|
349
464
|
end
|
350
|
-
end
|
465
|
+
end
|
466
|
+
a.join(sep)
|
351
467
|
end
|
352
468
|
|
353
469
|
NEED_QUOTE = %w[
|
@@ -357,21 +473,16 @@ class Gnuplot
|
|
357
473
|
commentschars
|
358
474
|
dashtype
|
359
475
|
decimalsign
|
360
|
-
|
361
|
-
font
|
476
|
+
file
|
362
477
|
fontpath
|
363
478
|
format
|
364
|
-
format_cb
|
365
|
-
format_x
|
366
|
-
format_x2
|
367
|
-
format_xy
|
368
|
-
format_y
|
369
|
-
format_y2
|
370
|
-
format_z
|
371
479
|
locale
|
372
480
|
logfile
|
373
481
|
missing
|
482
|
+
name
|
483
|
+
newhistogram
|
374
484
|
output
|
485
|
+
prefix
|
375
486
|
print
|
376
487
|
rgb
|
377
488
|
separator
|
@@ -383,52 +494,96 @@ class Gnuplot
|
|
383
494
|
y2label
|
384
495
|
ylabel
|
385
496
|
zlabel
|
386
|
-
cb
|
387
|
-
x
|
388
497
|
xy
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
498
|
+
]
|
499
|
+
NONEED_QUOTE = %w[
|
500
|
+
for
|
501
|
+
log
|
502
|
+
smooth
|
393
503
|
]
|
394
504
|
|
395
505
|
def NEED_QUOTE.===(k)
|
506
|
+
k = $1 if /_([^_]+)$/ =~ k
|
396
507
|
re = /^#{k}/
|
508
|
+
return false if NONEED_QUOTE.any?{|q| re =~ q}
|
397
509
|
any?{|q| re =~ q}
|
398
510
|
end
|
399
511
|
|
400
|
-
def
|
401
|
-
case
|
512
|
+
def quote(s)
|
513
|
+
case s
|
514
|
+
when String
|
515
|
+
if /^'(.*)'$/ =~ s || /^"(.*)"$/ =~ s
|
516
|
+
s = $1
|
517
|
+
end
|
518
|
+
s.inspect
|
519
|
+
else
|
520
|
+
s
|
521
|
+
end
|
522
|
+
end
|
523
|
+
|
524
|
+
def squote(s)
|
525
|
+
case s
|
526
|
+
when String
|
527
|
+
if /^'.*'$/ =~ s || /^".*"$/ =~ s
|
528
|
+
s
|
529
|
+
else
|
530
|
+
"'#{s}'"
|
531
|
+
end
|
532
|
+
else
|
533
|
+
s
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
def parse_kv(s,v)
|
538
|
+
k = from_symbol(s)
|
539
|
+
case s.to_sym
|
402
540
|
when :at
|
403
541
|
case v
|
404
542
|
when String
|
405
543
|
"#{k} #{v}" # not quote
|
406
544
|
when Array
|
407
|
-
"#{k} #{v.map{|x|
|
545
|
+
"#{k} #{v.map{|x| x.to_s}.join(",")}"
|
408
546
|
else
|
409
547
|
"#{k} #{parse(v)}"
|
410
548
|
end
|
411
549
|
when :label
|
412
550
|
case v
|
413
551
|
when String
|
414
|
-
"#{k} #{v
|
552
|
+
"#{k} #{OptArg.quote(v)}"
|
415
553
|
when Array
|
416
554
|
if v[0].kind_of?(Integer) && v[1].kind_of?(String)
|
417
|
-
"#{k} #{parse(v[0],v[1]
|
555
|
+
"#{k} #{parse(v[0],OptArg.quote(v[1]),*v[2..-1])}"
|
418
556
|
elsif v[0].kind_of?(String)
|
419
|
-
"#{k} #{parse(v[0]
|
557
|
+
"#{k} #{parse(OptArg.quote(v[0]),*v[1..-1])}"
|
420
558
|
else
|
421
559
|
"#{k} #{parse(*v)}"
|
422
560
|
end
|
561
|
+
when TrueClass
|
562
|
+
k
|
423
563
|
else
|
424
564
|
"#{k} #{parse(v)}"
|
425
565
|
end
|
426
566
|
when NEED_QUOTE
|
427
567
|
case v
|
428
568
|
when String
|
429
|
-
"#{k
|
569
|
+
"#{k} #{OptArg.quote(v)}"
|
570
|
+
when TrueClass
|
571
|
+
k
|
572
|
+
when NilClass
|
573
|
+
nil
|
574
|
+
when FalseClass
|
575
|
+
nil
|
430
576
|
when Array
|
431
|
-
|
577
|
+
case v[0]
|
578
|
+
when String
|
579
|
+
if v.size == 1
|
580
|
+
"#{k} #{OptArg.quote(v[0])}"
|
581
|
+
else
|
582
|
+
"#{k} #{OptArg.quote(v[0])} #{parse(*v[1..-1])}"
|
583
|
+
end
|
584
|
+
else
|
585
|
+
"#{k} #{parse(*v)}"
|
586
|
+
end
|
432
587
|
else
|
433
588
|
"#{k} #{parse(v)}"
|
434
589
|
end
|
@@ -437,14 +592,17 @@ class Gnuplot
|
|
437
592
|
when String
|
438
593
|
"#{k} #{v}"
|
439
594
|
when TrueClass
|
440
|
-
|
595
|
+
k
|
441
596
|
when NilClass
|
442
597
|
nil
|
443
598
|
when FalseClass
|
444
599
|
nil
|
445
600
|
when Array
|
446
|
-
|
601
|
+
re = /^#{k}/
|
602
|
+
if re =~ "using" || re =~ "every"
|
447
603
|
"#{k} #{v.join(':')}"
|
604
|
+
elsif v.empty?
|
605
|
+
k
|
448
606
|
else
|
449
607
|
"#{k} #{parse(*v)}"
|
450
608
|
end
|
@@ -501,7 +659,7 @@ class Gnuplot
|
|
501
659
|
if (o=@items.last).kind_of? Hash
|
502
660
|
if o.any?{|k,v| /^#{k}/ =~ "using"}
|
503
661
|
# @function is data file
|
504
|
-
@function =
|
662
|
+
@function = OptArg.squote(@function)
|
505
663
|
end
|
506
664
|
end
|
507
665
|
else
|
@@ -514,7 +672,11 @@ class Gnuplot
|
|
514
672
|
@options << x
|
515
673
|
end
|
516
674
|
end
|
517
|
-
|
675
|
+
if data.empty?
|
676
|
+
@function = ''
|
677
|
+
else
|
678
|
+
@data = parse_data(data)
|
679
|
+
end
|
518
680
|
end
|
519
681
|
end
|
520
682
|
end
|
@@ -544,6 +706,27 @@ class Gnuplot
|
|
544
706
|
end # PlotItem
|
545
707
|
|
546
708
|
|
709
|
+
# @private
|
710
|
+
class FitItem # :nodoc: all
|
711
|
+
def initialize(expression,datafile)
|
712
|
+
@expression = expression
|
713
|
+
@datafile = datafile
|
714
|
+
@items = []
|
715
|
+
end
|
716
|
+
|
717
|
+
def <<(item)
|
718
|
+
@items << item
|
719
|
+
end
|
720
|
+
|
721
|
+
def empty?
|
722
|
+
@items.empty?
|
723
|
+
end
|
724
|
+
|
725
|
+
def cmd_str
|
726
|
+
"%s %s %s" % [@expression, OptArg.squote(@datafile), OptArg.parse(*@items)]
|
727
|
+
end
|
728
|
+
end
|
729
|
+
|
547
730
|
# @private
|
548
731
|
class SPlotItem < PlotItem # :nodoc: all
|
549
732
|
def parse_data(data)
|
@@ -567,6 +750,9 @@ class Gnuplot
|
|
567
750
|
end
|
568
751
|
|
569
752
|
def initialize(*data)
|
753
|
+
if data.empty?
|
754
|
+
raise ArgumentError,"no data"
|
755
|
+
end
|
570
756
|
@data = data.map{|a| a.flatten}
|
571
757
|
@n = @data.map{|a| a.size}.min
|
572
758
|
@text = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: numo-gnuplot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- LICENSE
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
|
+
- examples/Rakefile
|
53
54
|
- examples/all.rb
|
54
55
|
- examples/ex001.rb
|
55
56
|
- examples/ex002.rb
|