numo-gnuplot 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/ToDo +5 -0
- data/examples/Rakefile +4 -0
- data/lib/numo/gnuplot.rb +175 -21
- 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: c624c33da64f76b0b4f072f55918c6e1b5ae7a2d
|
4
|
+
data.tar.gz: 8209e3093a40fcf2219cc71be057022fc329eac1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb122b78463ec953a1a9fea7a3957c4724c7ba7fed987b2c68bfa5368c85468e20ee244f75ad60ad587f13625e823ad835aa202c3916113a1832dc4340399132
|
7
|
+
data.tar.gz: c0061a69f0d39943c8e2eb2d83bc2ee71429d702f87d67edecc63174d32de7ef6b7ce8c13aa6704fc58b0ad6a875858bb19361c86e7edf75847bb0689b54679b
|
data/README.md
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
# Numo::Gnuplot : Gnuplot interface for Ruby
|
2
2
|
|
3
|
-
|
3
|
+
Alpha version under development.
|
4
|
+
|
4
5
|
* [GitHub site](https://github.com/ruby-numo/gnuplot)
|
5
6
|
* [RubyGems site](https://rubygems.org/gems/numo-gnuplot)
|
6
|
-
* [
|
7
|
+
* [Demo repository](https://github.com/ruby-numo/numo-gnuplot-demo)
|
7
8
|
|
8
|
-
*
|
9
|
+
* [API doc](http://www.rubydoc.info/gems/numo-gnuplot/Numo/Gnuplot)
|
10
|
+
* [Introduction.ja](https://github.com/ruby-numo/gnuplot/wiki/Introduction.ja) (in Japanese)
|
9
11
|
|
10
12
|
Although there are many [other Gnuplot interface libraries for Ruby](https://github.com/ruby-numo/gnuplot#related-work),
|
11
13
|
none of them have so simple interface as to show an XY data plot by just typing:
|
@@ -32,7 +34,7 @@ Or install it yourself as:
|
|
32
34
|
|
33
35
|
$ gem install numo-gnuplot
|
34
36
|
|
35
|
-
## Demo
|
37
|
+
## Demo
|
36
38
|
|
37
39
|
* [Ruby/Numo::Gnuplot Demo](https://github.com/ruby-numo/numo-gnuplot-demo)
|
38
40
|
|
data/ToDo
ADDED
data/examples/Rakefile
CHANGED
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.1"
|
22
22
|
POOL = []
|
23
23
|
DATA_FORMAT = "%.7g"
|
24
24
|
|
@@ -89,7 +89,7 @@ class Gnuplot
|
|
89
89
|
|
90
90
|
def _plot_splot(cmd,contents)
|
91
91
|
r = contents.shift.map{|x| "#{x} "}.join
|
92
|
-
c = contents.map{|x| x.cmd_str}.join(",")
|
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
95
|
nil
|
@@ -230,7 +230,8 @@ class Gnuplot
|
|
230
230
|
|
231
231
|
# output current plot to file with terminal setting from extension
|
232
232
|
# (not Gnuplot command)
|
233
|
-
def output(filename
|
233
|
+
def output(filename,**opts)
|
234
|
+
term = opts.delete(:term) || opts.delete(:terminal)
|
234
235
|
if term.nil? && /\.(\w+)$/ =~ filename
|
235
236
|
term = $1
|
236
237
|
end
|
@@ -238,7 +239,7 @@ class Gnuplot
|
|
238
239
|
if term.nil?
|
239
240
|
kernel_raise GnuplotError,"file extension is not given"
|
240
241
|
end
|
241
|
-
set terminal
|
242
|
+
set :terminal, term, *opts
|
242
243
|
set output:filename
|
243
244
|
refresh
|
244
245
|
unset :terminal
|
@@ -305,7 +306,53 @@ class Gnuplot
|
|
305
306
|
end
|
306
307
|
|
307
308
|
def send_cmd(s,data=nil)
|
308
|
-
|
309
|
+
if @debug
|
310
|
+
puts "<"+s
|
311
|
+
if data && !data.empty?
|
312
|
+
if data.size > 144
|
313
|
+
s1 = data[0..71]
|
314
|
+
s2 = data[-72..-1]
|
315
|
+
if s1.force_encoding("UTF-8").ascii_only? &&
|
316
|
+
s2.force_encoding("UTF-8").ascii_only?
|
317
|
+
a = [nil]*6
|
318
|
+
if /\A(.+?)$(.+)?/m =~ s1
|
319
|
+
a[0..1] = $1,$2
|
320
|
+
if a[1] && /\A(.+?)?$(.+)?/m =~ a[1].strip
|
321
|
+
a[1..2] = $1,$2
|
322
|
+
a[1] = a[1]+"..." if !a[2]
|
323
|
+
else
|
324
|
+
a[0] = a[0]+"..."
|
325
|
+
end
|
326
|
+
end
|
327
|
+
if /(.+)?^(.+?)\z/m =~ s2
|
328
|
+
a[4..5] = $1,$2
|
329
|
+
if a[4] && /(.+)?^(.+?)?\z/m =~ a[4].strip
|
330
|
+
a[3..4] = $1,$2
|
331
|
+
a[4] = "..."+a[4] if !a[3]
|
332
|
+
else
|
333
|
+
a[5] = "..."+a[5]
|
334
|
+
end
|
335
|
+
end
|
336
|
+
if a[2] || a[3]
|
337
|
+
a[2..3] = ["...",nil]
|
338
|
+
end
|
339
|
+
a.each{|l| puts "<"+l if l}
|
340
|
+
else
|
341
|
+
c = data[0..31].inspect
|
342
|
+
c += "..." if data.size > 32
|
343
|
+
puts "<"+c
|
344
|
+
end
|
345
|
+
else
|
346
|
+
if data.force_encoding("UTF-8").ascii_only?
|
347
|
+
data.split(/\n/).each{|l| puts "<"+l}
|
348
|
+
else
|
349
|
+
c = data[0..31].inspect
|
350
|
+
c += "..." if data.size > 32
|
351
|
+
puts "<"+c
|
352
|
+
end
|
353
|
+
end
|
354
|
+
end
|
355
|
+
end
|
309
356
|
@iow.puts s
|
310
357
|
@iow.puts data
|
311
358
|
@iow.flush
|
@@ -670,6 +717,13 @@ class Gnuplot
|
|
670
717
|
data << x
|
671
718
|
else
|
672
719
|
@options << x
|
720
|
+
if x.kind_of? Hash
|
721
|
+
x.each do |k,v|
|
722
|
+
if /^#{k}/ =~ "with"
|
723
|
+
@style = v; break;
|
724
|
+
end
|
725
|
+
end
|
726
|
+
end
|
673
727
|
end
|
674
728
|
end
|
675
729
|
if data.empty?
|
@@ -681,8 +735,21 @@ class Gnuplot
|
|
681
735
|
end
|
682
736
|
end
|
683
737
|
|
738
|
+
def parse_data_style(data)
|
739
|
+
if @style
|
740
|
+
re = /^#{@style}/
|
741
|
+
if re =~ "image"
|
742
|
+
return ImageData.new(*data)
|
743
|
+
elsif re =~ "rgbimage"
|
744
|
+
return RgbImageData.new(*data)
|
745
|
+
elsif re =~ "rgbalpha"
|
746
|
+
return RgbAlphaData.new(*data)
|
747
|
+
end
|
748
|
+
end
|
749
|
+
end
|
750
|
+
|
684
751
|
def parse_data(data)
|
685
|
-
PlotData.new(*data)
|
752
|
+
parse_data_style(data) || PlotData.new(*data)
|
686
753
|
end
|
687
754
|
|
688
755
|
def cmd_str
|
@@ -730,21 +797,17 @@ class Gnuplot
|
|
730
797
|
# @private
|
731
798
|
class SPlotItem < PlotItem # :nodoc: all
|
732
799
|
def parse_data(data)
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
else
|
737
|
-
PlotData.new(*data)
|
738
|
-
end
|
739
|
-
else
|
800
|
+
parse_data_style(data) ||
|
801
|
+
(data.size == 1) ?
|
802
|
+
ImageData.new(data.first) :
|
740
803
|
SPlotRecord.new(*data)
|
741
|
-
end
|
742
804
|
end
|
743
805
|
end
|
744
806
|
|
745
807
|
|
746
808
|
# @private
|
747
809
|
class PlotData # :nodoc: all
|
810
|
+
|
748
811
|
def data_format
|
749
812
|
@data_format || DATA_FORMAT
|
750
813
|
end
|
@@ -866,17 +929,60 @@ class Gnuplot
|
|
866
929
|
end
|
867
930
|
|
868
931
|
# @private
|
869
|
-
class
|
932
|
+
class ImageData < PlotData # :nodoc: all
|
933
|
+
|
934
|
+
def check_shape
|
935
|
+
if @data.shape.size != 2
|
936
|
+
raise IndexError,"array should be 2-dimensional"
|
937
|
+
end
|
938
|
+
@shape = @data.shape
|
939
|
+
end
|
940
|
+
|
870
941
|
def initialize(data)
|
871
|
-
@
|
942
|
+
@text = false
|
943
|
+
if data.respond_to?(:shape)
|
944
|
+
@data = data
|
945
|
+
check_shape
|
946
|
+
if defined? Numo::NArray
|
947
|
+
@format =
|
948
|
+
case @data
|
949
|
+
when Numo::DFloat; "%float64"
|
950
|
+
when Numo::SFloat; "%float32"
|
951
|
+
when Numo::Int8; "%int8"
|
952
|
+
when Numo::UInt8; "%uint8"
|
953
|
+
when Numo::Int16; "%int16"
|
954
|
+
when Numo::UInt16; "%uint16"
|
955
|
+
when Numo::Int32; "%int32"
|
956
|
+
when Numo::UInt32; "%uint32"
|
957
|
+
when Numo::Int64; "%int64"
|
958
|
+
when Numo::UInt64; "%uint64"
|
959
|
+
else
|
960
|
+
raise ArgumentError,"not supported NArray type"
|
961
|
+
end
|
962
|
+
end
|
963
|
+
elsif data.kind_of? Array
|
964
|
+
n = nil
|
965
|
+
@data = []
|
966
|
+
data.each do |a|
|
967
|
+
@data.concat(a)
|
968
|
+
m = a.size
|
969
|
+
if n && n != m
|
970
|
+
raise IndexError,"element size differs (%d should be %d)"%[m, n]
|
971
|
+
end
|
972
|
+
n = m
|
973
|
+
end
|
974
|
+
@shape = [data.size,n]
|
975
|
+
@format = "%float64"
|
976
|
+
else
|
977
|
+
raise ArgumentError,"argument should be data array"
|
978
|
+
end
|
872
979
|
end
|
873
980
|
|
874
981
|
def cmd_str
|
875
982
|
if @text
|
876
983
|
"'-' matrix"
|
877
984
|
else
|
878
|
-
|
879
|
-
"'-' binary array=(#{s[1]},#{s[0]}) format='%float64'"
|
985
|
+
"'-' binary array=(#{@shape[1]},#{@shape[0]}) format='#{@format}'"
|
880
986
|
end
|
881
987
|
end
|
882
988
|
|
@@ -884,15 +990,63 @@ class Gnuplot
|
|
884
990
|
if @text
|
885
991
|
f = data_format
|
886
992
|
s = ""
|
887
|
-
|
993
|
+
@data.to_a.each do |b|
|
888
994
|
s << b.map{|e| f%e}.join(" ")+"\n"
|
889
995
|
end
|
890
996
|
s+"\ne"
|
891
997
|
elsif defined? Numo::NArray
|
892
|
-
Numo::
|
998
|
+
if @data.kind_of?(Numo::NArray)
|
999
|
+
@data.to_string
|
1000
|
+
else
|
1001
|
+
Numo::DFloat.cast(@data).to_string
|
1002
|
+
end
|
893
1003
|
else
|
894
|
-
@data.
|
1004
|
+
@data.pack("d*")
|
1005
|
+
end
|
1006
|
+
end
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
# @private
|
1010
|
+
class RgbImageData < ImageData # :nodoc: all
|
1011
|
+
|
1012
|
+
def initialize(data)
|
1013
|
+
if data.kind_of?(Numo::NArray)
|
1014
|
+
super(data)
|
1015
|
+
else
|
1016
|
+
super(Numo::NArray[*data])
|
1017
|
+
end
|
1018
|
+
end
|
1019
|
+
|
1020
|
+
def check_shape
|
1021
|
+
if @data.shape.size != 3
|
1022
|
+
raise IndexError,"array should be 2-dimensional"
|
1023
|
+
end
|
1024
|
+
if @data.shape[2] != 3
|
1025
|
+
raise IndexError,"shape[2] (last dimension size) must be 3"
|
1026
|
+
end
|
1027
|
+
@shape = @data.shape
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
# @private
|
1032
|
+
class RgbAlphaData < ImageData # :nodoc: all
|
1033
|
+
|
1034
|
+
def initialize(data)
|
1035
|
+
if data.kind_of?(Numo::NArray)
|
1036
|
+
super(data)
|
1037
|
+
else
|
1038
|
+
super(Numo::NArray[*data])
|
1039
|
+
end
|
1040
|
+
end
|
1041
|
+
|
1042
|
+
def check_shape
|
1043
|
+
if @data.shape.size != 3
|
1044
|
+
raise IndexError,"array should be 2-dimensional"
|
1045
|
+
end
|
1046
|
+
if @data.shape[2] != 4
|
1047
|
+
raise IndexError,"shape[2] (last dimension size) must be 4"
|
895
1048
|
end
|
1049
|
+
@shape = @data.shape
|
896
1050
|
end
|
897
1051
|
end
|
898
1052
|
|
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.1
|
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-01-
|
11
|
+
date: 2017-01-20 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
|
+
- ToDo
|
53
54
|
- examples/Rakefile
|
54
55
|
- examples/all.rb
|
55
56
|
- examples/ex001.rb
|