Sha256: 86140e5816e78a21217210a6b1f6198f3f2276f6000cbaa68221ebdadacb3212

Contents?: true

Size: 1.34 KB

Versions: 2

Compression:

Stored size: 1.34 KB

Contents

require 'nyaplot' unless defined? Nyaplot

module Mikon
  class Series
    def plot(args={})
      args = {
        :type => :histogram
      }.merge(args)

      plot = Nyaplot::Plot.new

      case args[:type]
      when :histogram
        plot.add(:histogram, @data.to_a)
      when :line
        plot.add(:line, @index, @data.to_a)
      end

      plot
    end
  end

  class DataFrame
    def plot(args={})
      args = {
        :type => :line,
        :x => nil,
        :y => nil,
        :fill_by => nil,
        :color => nil
      }.merge(args)

      plot = Nyaplot::Plot.new
      plot.x_label("")
      plot.y_label("")

      unless args[:color].nil?
        colors = Nyaplot::Colors.send(args[:color]).to_a
      else
        colors = Nyaplot::Colors.qual.to_a
      end

      case args[:type]
      when :line
        @data.each.with_index do |darr, i|
          line = plot.add(:line, @index, darr.to_a)
          line.color(colors.pop)
          line.title(@labels[i])
        end
        plot.legend(true)

      when :box
        plot.add_with_df(self, :box, *@labels)

      when :scatter
        sc = plot.add_with_df(self, :scatter, args[:x], args[:y])
        sc.color(colors)
        sc.fill_by(args[:fill_by]) unless args[:fill_by].nil?
        plot.x_label(args[:x])
        plot.y_label(args[:y])
      end

      plot
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mikon-0.1.3 lib/mikon/plot.rb
mikon-0.1.2.rc1 lib/mikon/plot.rb