Method: GnuplotRB::Multiplot#update_plot

Defined in:
lib/gnuplotrb/multiplot.rb

#update_plot(position = 0, **options) {|plot| ... } ⇒ Multiplot Also known as: update

Create new updated Multiplot object where plot (Plot or Splot object) at position will be replaced with the new one created from it by updating. To update a plot you can pass some options for it or a block, that should take existing plot (with new options if you gave them) and return a plot too.

Method yields new created Plot or Splot to allow you update it manually.

Examples:

mp = Multiplot.new(Plot.new('sin(x)'), Plot.new('cos(x)'), layout: [2,1])
updated_mp = mp.update_plot(title: 'Sin(x) and Exp(x)') { |sinx| sinx.add!('exp(x)') }
# mp IS NOT affected

Parameters:

  • position (Integer) (defaults to: 0)

    position of plot which you need to update (by default first plot is updated)

  • options (Hash)

    options to set into updated plot

Yield Parameters:

Yield Returns:

Returns:



78
79
80
81
82
83
# File 'lib/gnuplotrb/multiplot.rb', line 78

def update_plot(position = 0, **options)
  return self unless block_given? if options.empty?
  replacement = @plots[position].options(options)
  replacement = yield(replacement) if block_given?
  replace_plot(position, replacement)
end