numo-gnuplot 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5064afaa692cccf4077c9492ab467cefa3ef796
4
- data.tar.gz: 5ffb4ca3e9186be9f407d78574c6d3a1c28f9967
3
+ metadata.gz: 23318f9476abeabe7f3b1cf973750b8a6e4a84b0
4
+ data.tar.gz: 94534cf81c5e11030deddebfa2ff4507dc35ee2b
5
5
  SHA512:
6
- metadata.gz: 270d969fb495edcbcbaef29c48e4047e1d9b9e501ed027203109534ee89fcde62fcef8eb945fa7b92a4c8d29d47a7a01bb2ef142edb3422e4ab7e87867ec14ec
7
- data.tar.gz: 0f88298db5e01193da0fc5aa848c56f3b98b365b798192d9bd5d8fcf091b644bd18ae0888a91f5b2ec52a9831d9dd94da77daa813eee726786a2f4536f136500
6
+ metadata.gz: 2f9e70d4c27142494d857a0fba1ae7c0a3bdd8d9f31095a18c8a08621d309275067224a519eac14218c168a5a8b684ea559d0c99d9405737d5b7be6bb6894632
7
+ data.tar.gz: a90ac0f94296c4828317087d408b64c408233cd7c84ed9da8956ca9fc29add975712d2af9378fa3cb89340d9ea509831825f40758f1d1c12ecf6c007ccae0da6
data/README.md CHANGED
@@ -153,6 +153,25 @@ Numo.gnuplot do
153
153
  end
154
154
  ```
155
155
 
156
+ ### IRuby
157
+ Numo::Gnuplot is compatible with [IRuby](https://github.com/SciRuby/iruby/).
158
+
159
+ * Embedding a plot into iRuby Notebook.
160
+
161
+ ```ruby
162
+ Numo::Gnuplot::NotePlot.new do
163
+ plot "sin(x)"
164
+ end
165
+ ```
166
+
167
+ * The same thing in short.
168
+
169
+ ```ruby
170
+ Numo.noteplot do
171
+ plot "sin(x)"
172
+ end
173
+ ```
174
+
156
175
  ## Gnuplot methods
157
176
 
158
177
  Numo::Gnuplot class methods succeeded from Gnuplot commands:
@@ -0,0 +1,11 @@
1
+ x = ['a','b','c','d','e']
2
+ y = [10,20,40,30,45]
3
+
4
+ Numo.gnuplot do
5
+ set title:'Bar chart with text labels'
6
+ set boxwidth:0.5
7
+ set 'grid'
8
+ set yrange:[0..50]
9
+ set style:[fill:'solid']
10
+ plot x,y, using:[2, 'xtic(1)'], w:'boxes', t:'series'
11
+ end
@@ -9,9 +9,14 @@ module Numo
9
9
  end
10
10
  module_function :gnuplot
11
11
 
12
+ def noteplot(&block)
13
+ Gnuplot::NotePlot.new(&block)
14
+ end
15
+ module_function :noteplot
16
+
12
17
  class Gnuplot
13
18
 
14
- VERSION = "0.1.5"
19
+ VERSION = "0.1.6"
15
20
  POOL = []
16
21
  DATA_FORMAT = "%.7g"
17
22
 
@@ -21,6 +26,29 @@ class Gnuplot
21
26
  POOL[0] ||= self.new
22
27
  end
23
28
 
29
+ class NotePlot
30
+ def initialize(&block)
31
+ if block.nil?
32
+ raise ArgumentError,"block is needed"
33
+ end
34
+ @block = block
35
+ end
36
+
37
+ def to_iruby
38
+ require 'tempfile'
39
+ tempfile_svg = Tempfile.open('plot')
40
+ # output SVG to tmpfile
41
+ gp = Gnuplot.default
42
+ gp.reset
43
+ gp.set terminal:'svg', output:tempfile_svg.path
44
+ gp.instance_eval(&@block)
45
+ gp.unset 'output'
46
+ svg = File.read(tempfile_svg.path)
47
+ tempfile_svg.close
48
+ ["image/svg+xml",svg]
49
+ end
50
+ end
51
+
24
52
  def initialize(gnuplot_command="gnuplot")
25
53
  @history = []
26
54
  @debug = false
@@ -554,7 +582,7 @@ class Gnuplot
554
582
  s = v.to_s
555
583
  if /"/ =~ s
556
584
  kernel_raise GnuplotError,"should not include double quotation in data"
557
- elsif / / =~ s
585
+ else
558
586
  s = '"'+s+'"'
559
587
  end
560
588
  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.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masahiro TANAKA
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-03 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,6 +57,7 @@ files:
57
57
  - examples/ex004.rb
58
58
  - examples/ex005.rb
59
59
  - examples/ex006.rb
60
+ - examples/ex007.rb
60
61
  - examples/ex010.rb
61
62
  - examples/ex011.rb
62
63
  - lib/numo/gnuplot.rb