numo-gnuplot 0.2.3 → 0.2.4
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.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/lib/numo/gnuplot.rb +81 -55
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bea55aa439ccecdaa82be80cac6ecc3e55e2a78
|
4
|
+
data.tar.gz: 3ba14d97891fbc339afcf79dd20f6bfad7b85f17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7edf347b3c9c63622da94fc7e75205f26a55f2b2a52520b4b03c4555ed97fb191ee0941d9e0a554232d021e7f00ab1e0a45deff8bdffd684002dfabf5abb260
|
7
|
+
data.tar.gz: 5682b191f24182db3255b25f748ab4fe0950f5dfda67b7b0169ce69a77b965b22057695566b6e29e868a11ce3b06d24835bf6fb006e2a7f82df2c40d0911cd07
|
data/README.md
CHANGED
@@ -1,5 +1,26 @@
|
|
1
1
|
# Numo::Gnuplot : Gnuplot interface for Ruby
|
2
2
|
|
3
|
+
<div class="row">
|
4
|
+
<a href=https://github.com/ruby-numo/gnuplot-demo/blob/master/gnuplot/md/006histograms/README.md>
|
5
|
+
<img src="https://raw.githubusercontent.com/ruby-numo/gnuplot-demo/master/gnuplot/md/006histograms/image/006.png" height="135" width="135">
|
6
|
+
</a>
|
7
|
+
<a href=https://github.com/ruby-numo/gnuplot-demo/blob/master/gnuplot/md/501rainbow/README.md>
|
8
|
+
<img src="https://raw.githubusercontent.com/ruby-numo/gnuplot-demo/master/gnuplot/md/501rainbow/image/002.png" height="135" width="135">
|
9
|
+
</a>
|
10
|
+
<a href=https://github.com/ruby-numo/gnuplot-demo/blob/master/gnuplot/md/603finance/README.md>
|
11
|
+
<img src="https://raw.githubusercontent.com/ruby-numo/gnuplot-demo/master/gnuplot/md/603finance/image/013.png" height="135" width="135">
|
12
|
+
</a>
|
13
|
+
<a href=https://github.com/ruby-numo/gnuplot-demo/blob/master/gnuplot/md/502rgb_variable/README.md>
|
14
|
+
<img src="https://raw.githubusercontent.com/ruby-numo/gnuplot-demo/master/gnuplot/md/502rgb_variable/image/006.png" height="135" width="135">
|
15
|
+
</a>
|
16
|
+
<a href=https://github.com/ruby-numo/gnuplot-demo/blob/master/gnuplot/md/207hidden2/README.md>
|
17
|
+
<img src="https://raw.githubusercontent.com/ruby-numo/gnuplot-demo/master/gnuplot/md/207hidden2/image/001.png" height="135" width="135">
|
18
|
+
</a>
|
19
|
+
<a href=https://github.com/ruby-numo/gnuplot-demo/blob/master/gnuplot/md/905transparent_solids/README.md>
|
20
|
+
<img src="https://raw.githubusercontent.com/ruby-numo/gnuplot-demo/master/gnuplot/md/905transparent_solids/image/002.png" height="135" width="135">
|
21
|
+
</a>
|
22
|
+
</div>
|
23
|
+
|
3
24
|
Alpha version under development.
|
4
25
|
|
5
26
|
* [GitHub site](https://github.com/ruby-numo/gnuplot)
|
data/lib/numo/gnuplot.rb
CHANGED
@@ -18,7 +18,7 @@ module Numo
|
|
18
18
|
|
19
19
|
class Gnuplot
|
20
20
|
|
21
|
-
VERSION = "0.2.
|
21
|
+
VERSION = "0.2.4"
|
22
22
|
POOL = []
|
23
23
|
DATA_FORMAT = "%.7g"
|
24
24
|
|
@@ -92,13 +92,14 @@ class Gnuplot
|
|
92
92
|
c = contents.map{|x| x.cmd_str}.join(", ")
|
93
93
|
d = contents.map{|x| x.data_str}.join
|
94
94
|
run "#{cmd} #{r}#{c}", d
|
95
|
+
@last_data = d
|
95
96
|
nil
|
96
97
|
end
|
97
98
|
private :_plot_splot
|
98
99
|
|
99
100
|
# replot is not recommended, use refresh
|
100
101
|
def replot(arg=nil)
|
101
|
-
run "replot #{arg}
|
102
|
+
run "replot #{arg}", @last_data
|
102
103
|
nil
|
103
104
|
end
|
104
105
|
|
@@ -118,13 +119,13 @@ class Gnuplot
|
|
118
119
|
# in the `fit`section). This is useful for saving the current
|
119
120
|
# values for later use or for restarting a converged or stopped fit.
|
120
121
|
def update(*filenames)
|
121
|
-
puts send_cmd("update "+filenames.map{|f| OptArg.
|
122
|
+
puts send_cmd("update "+filenames.map{|f| OptArg.quote(f)}.join(" "))
|
122
123
|
end
|
123
124
|
|
124
125
|
# This command prepares a statistical summary of the data in one or
|
125
126
|
# two columns of a file.
|
126
127
|
def stats(filename,*args)
|
127
|
-
fn = OptArg.
|
128
|
+
fn = OptArg.quote(filename)
|
128
129
|
opt = OptArg.parse(*args)
|
129
130
|
puts send_cmd "stats #{fn} #{opt}"
|
130
131
|
end
|
@@ -171,7 +172,7 @@ class Gnuplot
|
|
171
172
|
|
172
173
|
# The `load` command executes each line of the specified input file.
|
173
174
|
def load(filename)
|
174
|
-
run "load #{OptArg.
|
175
|
+
run "load #{OptArg.quote(filename)}"
|
175
176
|
nil
|
176
177
|
end
|
177
178
|
|
@@ -294,7 +295,7 @@ class Gnuplot
|
|
294
295
|
return nil
|
295
296
|
end
|
296
297
|
if res.size < 7
|
297
|
-
if
|
298
|
+
if /^\s*(line \d+: )?warning:/i =~ res[0]
|
298
299
|
$stderr.puts res.join.strip
|
299
300
|
return nil
|
300
301
|
else
|
@@ -426,7 +427,7 @@ class Gnuplot
|
|
426
427
|
when 2
|
427
428
|
"[#{a[0]}:#{a[1]}]"
|
428
429
|
else
|
429
|
-
|
430
|
+
kernel_raise ArgumentError,"wrong number of argument"
|
430
431
|
end
|
431
432
|
end
|
432
433
|
private :range_to_s
|
@@ -498,6 +499,10 @@ class Gnuplot
|
|
498
499
|
if opts.first.kind_of?(String)
|
499
500
|
a << OptArg.quote(opts.shift)
|
500
501
|
end
|
502
|
+
when NEED_QUOTE_TIME
|
503
|
+
if opts.first.kind_of?(String)
|
504
|
+
a << OptArg.quote_time(opts.shift)
|
505
|
+
end
|
501
506
|
when NEED_QUOTE
|
502
507
|
if opts.first.kind_of?(String)
|
503
508
|
a << OptArg.quote(opts.shift)
|
@@ -516,6 +521,12 @@ class Gnuplot
|
|
516
521
|
a.join(sep)
|
517
522
|
end
|
518
523
|
|
524
|
+
NEED_QUOTE_TIME = /^timef(mt?)?/
|
525
|
+
|
526
|
+
def quote_time(s)
|
527
|
+
"'#{s}'"
|
528
|
+
end
|
529
|
+
|
519
530
|
NEED_QUOTE = %w[
|
520
531
|
background
|
521
532
|
cblabel
|
@@ -561,24 +572,10 @@ class Gnuplot
|
|
561
572
|
|
562
573
|
def quote(s)
|
563
574
|
case s
|
564
|
-
when
|
565
|
-
if /^'(.*)'$/ =~ s || /^"(.*)"$/ =~ s
|
566
|
-
s = $1
|
567
|
-
end
|
568
|
-
s.inspect
|
569
|
-
else
|
575
|
+
when /^('.*'|".*")$/
|
570
576
|
s
|
571
|
-
end
|
572
|
-
end
|
573
|
-
|
574
|
-
def squote(s)
|
575
|
-
case s
|
576
577
|
when String
|
577
|
-
|
578
|
-
s
|
579
|
-
else
|
580
|
-
"'#{s}'"
|
581
|
-
end
|
578
|
+
s.inspect
|
582
579
|
else
|
583
580
|
s
|
584
581
|
end
|
@@ -613,6 +610,8 @@ class Gnuplot
|
|
613
610
|
else
|
614
611
|
"#{k} #{parse(v)}"
|
615
612
|
end
|
613
|
+
when NEED_QUOTE_TIME
|
614
|
+
"#{k} #{OptArg.quote_time(v)}"
|
616
615
|
when NEED_QUOTE
|
617
616
|
case v
|
618
617
|
when String
|
@@ -677,13 +676,24 @@ class Gnuplot
|
|
677
676
|
t = Numeric if t < Numeric
|
678
677
|
return a.all?{|e| e.kind_of?(t)}
|
679
678
|
end
|
680
|
-
|
679
|
+
end
|
680
|
+
if defined?(Numo::NArray)
|
681
681
|
return true if a.kind_of?(Numo::NArray)
|
682
|
-
|
682
|
+
end
|
683
|
+
if defined?(::NArray)
|
683
684
|
return true if a.kind_of?(::NArray)
|
684
|
-
|
685
|
+
end
|
686
|
+
if defined?(::NMatrix)
|
685
687
|
return true if a.kind_of?(::NMatrix)
|
686
688
|
end
|
689
|
+
case a[a.size-1] # quick check for unknown data class
|
690
|
+
when Numeric
|
691
|
+
return true if a[0].kind_of?(Numeric)
|
692
|
+
when String
|
693
|
+
return true if a[0].kind_of?(String)
|
694
|
+
end
|
695
|
+
false
|
696
|
+
rescue
|
687
697
|
false
|
688
698
|
end
|
689
699
|
|
@@ -703,13 +713,13 @@ class Gnuplot
|
|
703
713
|
if !@options
|
704
714
|
if @items.empty?
|
705
715
|
return
|
706
|
-
elsif @items.first.kind_of?
|
716
|
+
elsif @items.first.kind_of?(String) || @items.first.kind_of?(Symbol)
|
707
717
|
@function = @items.first
|
708
718
|
@options = @items[1..-1]
|
709
719
|
if (o=@items.last).kind_of? Hash
|
710
720
|
if o.any?{|k,v| /^#{k}/ =~ "using"}
|
711
721
|
# @function is data file
|
712
|
-
@function = OptArg.
|
722
|
+
@function = OptArg.quote(@function)
|
713
723
|
end
|
714
724
|
end
|
715
725
|
else
|
@@ -793,7 +803,7 @@ class Gnuplot
|
|
793
803
|
end
|
794
804
|
|
795
805
|
def cmd_str
|
796
|
-
"%s %s %s" % [@expression, OptArg.
|
806
|
+
"%s %s %s" % [@expression, OptArg.quote(@datafile), OptArg.parse(*@items)]
|
797
807
|
end
|
798
808
|
end
|
799
809
|
|
@@ -819,7 +829,7 @@ class Gnuplot
|
|
819
829
|
if data.empty?
|
820
830
|
raise ArgumentError,"no data"
|
821
831
|
end
|
822
|
-
@data = data.map{|a| a.flatten}
|
832
|
+
@data = data.map{|a| a.respond_to?(:flatten) ? a.flatten : a}
|
823
833
|
@n = @data.map{|a| a.size}.min
|
824
834
|
@text = true
|
825
835
|
end
|
@@ -832,6 +842,15 @@ class Gnuplot
|
|
832
842
|
end
|
833
843
|
end
|
834
844
|
|
845
|
+
def as_array(a)
|
846
|
+
case a
|
847
|
+
when Numo::NArray,Array
|
848
|
+
a
|
849
|
+
else
|
850
|
+
a.to_a
|
851
|
+
end
|
852
|
+
end
|
853
|
+
|
835
854
|
def data_str
|
836
855
|
if @text
|
837
856
|
s = ""
|
@@ -840,7 +859,7 @@ class Gnuplot
|
|
840
859
|
elsif defined? Numo::NArray
|
841
860
|
m = @data.size
|
842
861
|
x = Numo::DFloat.zeros(@n,m)
|
843
|
-
m.times{|i| x[true,i] = @data[i][0...@n]}
|
862
|
+
m.times{|i| x[true,i] = as_array(@data[i])[0...@n]}
|
844
863
|
x.to_string
|
845
864
|
else
|
846
865
|
s = []
|
@@ -851,22 +870,27 @@ class Gnuplot
|
|
851
870
|
|
852
871
|
def line_str(i)
|
853
872
|
@data.map do |a|
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
873
|
+
PlotData.quote_data(a[i])
|
874
|
+
end.join(" ")
|
875
|
+
end
|
876
|
+
|
877
|
+
def self.quote_data(v)
|
878
|
+
case v
|
879
|
+
when Float,Rational
|
880
|
+
DATA_FORMAT % v
|
881
|
+
when Numeric
|
882
|
+
v.to_s
|
883
|
+
else
|
884
|
+
s = v.to_s.gsub(/\n/,'\n')
|
885
|
+
if /^(e|.*[ \t].*)$/ =~ s
|
862
886
|
if /"/ =~ s
|
863
|
-
|
864
|
-
|
865
|
-
s = '"'+s+'"'
|
887
|
+
raise GnuplotError,"Datastrings cannot include"+
|
888
|
+
" double quotation and space simultaneously"
|
866
889
|
end
|
890
|
+
s = '"'+s+'"'
|
867
891
|
end
|
868
892
|
s
|
869
|
-
end
|
893
|
+
end
|
870
894
|
end
|
871
895
|
|
872
896
|
def self.array_shape(a)
|
@@ -892,12 +916,14 @@ class Gnuplot
|
|
892
916
|
elsif is_2d
|
893
917
|
[a.size, size_min]
|
894
918
|
else
|
895
|
-
|
919
|
+
raise GnuplotError, "not suitable Array for data"
|
896
920
|
end
|
897
921
|
elsif a.respond_to?(:shape)
|
898
922
|
a.shape
|
923
|
+
elsif PlotItem.is_data(a)
|
924
|
+
[a.size]
|
899
925
|
else
|
900
|
-
|
926
|
+
raise GnuplotError, "not suitable type for data"
|
901
927
|
end
|
902
928
|
end
|
903
929
|
end
|
@@ -907,13 +933,13 @@ class Gnuplot
|
|
907
933
|
|
908
934
|
def initialize(x,y,z)
|
909
935
|
@text = false
|
910
|
-
@data = [x,y,z].map{|a| a.flatten}
|
936
|
+
@data = [x,y,z].map{|a| a.respond_to?(:flatten) ? a.flatten : a}
|
911
937
|
@n = @data.map{|a| a.size}.min
|
912
|
-
shape = PlotData.array_shape(
|
938
|
+
shape = PlotData.array_shape(@data[2])
|
913
939
|
if shape.size >= 2
|
914
940
|
n = shape[1]*shape[0]
|
915
941
|
if @n < n
|
916
|
-
|
942
|
+
raise GnuplotError, "data size mismatch"
|
917
943
|
end
|
918
944
|
@n = n
|
919
945
|
@record = "#{shape[1]},#{shape[0]}"
|
@@ -997,14 +1023,14 @@ class Gnuplot
|
|
997
1023
|
s << b.map{|e| f%e}.join(" ")+"\n"
|
998
1024
|
end
|
999
1025
|
s+"\ne"
|
1000
|
-
elsif defined? Numo::NArray
|
1001
|
-
|
1002
|
-
|
1003
|
-
else
|
1004
|
-
Numo::DFloat.cast(@data).to_string
|
1005
|
-
end
|
1006
|
-
else
|
1026
|
+
elsif defined? Numo::NArray && @data.kind_of?(Numo::NArray)
|
1027
|
+
@data.to_string
|
1028
|
+
elsif @data.kind_of?(Array)
|
1007
1029
|
@data.pack("d*")
|
1030
|
+
elsif @data.repond_to?(:to_a)
|
1031
|
+
@data.to_a.pack("d*")
|
1032
|
+
else
|
1033
|
+
raise TypeError,"invalid data type: #{@data.class}"
|
1008
1034
|
end
|
1009
1035
|
end
|
1010
1036
|
end
|
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.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masahiro TANAKA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|