Sha256: 91696f0ca4f1cda0d99c8e2de97e6e88d181d0d6f6547ee47917c5f6031c6172

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

begin
  require 'nyaplot'
rescue LoadError => e
  puts "#{e}"
end

module Daru
  module Plotting
    module Vector

      # Plots a Vector with Nyaplot on IRuby using the given options.
      # == 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, title: "My first plot", color: true
      def plot opts={}
        options = {
          type: :scatter,
          title: "#{@name}",
          x_label: '',
          y_label: '',
          color: false
        }.merge(opts)

        x_axis = options[:type] == :scatter ? Array.new(@size) { |i| i } : @index.to_a
        plot   = Nyaplot::Plot.new
        plot.width(options[:width])   if options[:width]
        plot.height(options[:height]) if options[:height]
        
        p      = plot.add( options[:type], x_axis, @vector.to_a )
        plot.x_label( options[:x_label] )  if options[:x_label]
        plot.y_label( options[:y_label] )  if options[:y_label]
        p.color( Nyaplot::Colors.qual )    if options[:color]

        plot.show
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daru-0.0.4 lib/daru/plotting/vector.rb