Class: Numo::Gnuplot::NotePlot

Inherits:
Object
  • Object
show all
Defined in:
lib/numo/gnuplot.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ NotePlot

Returns a new instance of NotePlot.


31
32
33
34
35
36
# File 'lib/numo/gnuplot.rb', line 31

def initialize(&block)
  if block.nil?
    raise ArgumentError,"block is needed"
  end
  @block = block
end

Instance Method Details

#to_irubyObject


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/numo/gnuplot.rb', line 38

def to_iruby
  require 'tempfile'
  tempfile_svg = Tempfile.open(['plot','.svg'])
  # output SVG to tmpfile
  gp = Gnuplot.default
  gp.reset
  gp.set terminal:'svg'
  gp.set output:tempfile_svg.path
  gp.instance_eval(&@block)
  gp.unset 'output'
  svg = File.read(tempfile_svg.path)
  tempfile_svg.close
  ["image/svg+xml",svg]
end