Method: GnuplotRB::Dataset#initialize

Defined in:
lib/gnuplotrb/staff/dataset.rb

#initialize(data, **options) ⇒ Dataset

Create new dataset out of given string with math function or filename. If data isn’t a string it will create datablock to store data.

Examples:

Math function:

Dataset.new('x*sin(x)', with: 'lines', lw: 4)

File with points:

Dataset.new('points.data', with: 'lines', title: 'Points from file')

Some data (creates datablock stored in memory):

x = (0..5000).to_a
y = x.map {|xx| xx*xx }
points = [x, y]
Dataset.new(points, with: 'points', title: 'Points')

The same data but datablock stores it in temp file:

Dataset.new(points, with: 'points', title: 'Points', file: true)

Parameters:

  • data (String, Datablock, #to_gnuplot_points)

    String, Datablock or something acceptable by Datablock.new as data (e.g. [x,y] where x and y are arrays)

  • options (Hash)

    options specific for gnuplot dataset (see Dataset top level doc), and some special options (‘file: true’ will make data to be stored inside temporary file)



65
66
67
68
# File 'lib/gnuplotrb/staff/dataset.rb', line 65

def initialize(data, **options)
  # run method by name
  send(INIT_HANDLERS[data.class], data, options)
end