Module: Daru::Plotting::Category::NyaplotLibrary

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

Instance Method Summary collapse

Instance Method Details

#plot(opts) ⇒ Object


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/daru/plotting/nyaplot/category.rb', line 5

def plot opts
  case type = opts[:type]
  when :bar
    plot = Nyaplot::Plot.new
    opts[:method] ||= :count
    values = frequencies opts[:method]
    diagram = plot.add :bar, values.index.to_a, values.to_a
    # Set yrange for good view
    set_yrange plot, opts[:method]
    yield plot, diagram if block_given?
    plot.show
  else
    raise ArgumentError, "#{type} type is not supported."
  end
end