Module: Daru::Plotting::Vector::NyaplotLibrary

Defined in:
lib/daru/plotting/nyaplot/vector.rb

Instance Method Summary collapse

Instance Method Details

#plot(opts = {}) {|plot, diagram| ... } ⇒ Object

Plots a Vector with Nyaplot on IRuby using the given options. Yields the plot object (Nyaplot::Plot) and the diagram object (Nyaplot::Diagram) to the block, which can be used for setting various options as per the Nyaplot API.

Options

type (:scatter, :bar, :histogram), title, x_label, y_label, color(true/false)

Usage

vector = Daru::Vector.new [10,20,30,40], [:one, :two, :three, :four]
vector.plot(type: :bar) do |plot|
  plot.title "My first plot"
  plot.width 1200
end

Yields:



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/daru/plotting/nyaplot/vector.rb', line 19

def plot opts={}
  options = {
    type: :scatter
  }.merge(opts)

  x_axis  = options[:type] == :scatter ? Array.new(size) { |i| i } : @index.to_a
  plot    = Nyaplot::Plot.new
  diagram = create_diagram plot, options[:type], x_axis

  yield plot, diagram if block_given?

  plot.show
end