Method: GnuplotRB::Animation#plot

Defined in:
lib/gnuplotrb/animation.rb

#plot(path = nil, **options) ⇒ nil, String

This method creates a gif animation where frames are plots already contained by Animation object.

Options passed in #plot have priority over those which were set before.

Inner options of Plots have the highest priority (except :term and :output which are ignored).

Parameters:

  • path (String) (defaults to: nil)

    path to new gif file that will be created as a result

  • options (Hash)

    see note about available options in top class documentation

Returns:

  • (nil)

    if path to output file given

  • (String)

    gif file contents if no path to output file given



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/gnuplotrb/animation.rb', line 55

def plot(path = nil, **options)
  options[:output] ||= path
  plot_options = mix_options(options) do |plot_opts, anim_opts|
    plot_opts.merge(term: ['gif', anim_opts])
  end.to_h
  need_output = plot_options[:output].nil?
  plot_options[:output] = Dir::Tmpname.make_tmpname('anim', 0) if need_output
  terminal = Terminal.new
  multiplot(terminal, plot_options)
  # guaranteed wait for plotting to finish
  terminal.close
  if need_output
    result = File.binread(plot_options[:output])
    File.delete(plot_options[:output])
  else
    result = nil
  end
  result
end