Class: Grada::Histogram

Inherits:
DefaultBase show all
Defined in:
lib/grada/types/histogram.rb

Class Method Summary collapse

Class Method Details

.plot(x, opts, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/grada/types/histogram.rb', line 3

def self.plot(x, opts, &block)
  Gnuplot.open do
    Gnuplot::Plot.construct do |plot|
      block.call plot if block 
      
      width = ( x.max - x.min ) / x.size

      plot.title opts[:title]
      
      plot.set "style data histogram"
      plot.xlabel opts[:x_label]
      plot.ylabel "Frequency"
      plot.set "style fill solid 0.5"
      plot.set "xrange [#{x.min}:#{x.max}]"
      plot.set "boxwidth #{ width * 0.1}"
      plot.set "xtics #{x.min},#{(x.max-x.min)/5},#{x.max}"
      plot.set "tics out nomirror"
  
      plot.data << Gnuplot::DataSet.new(x) do |ds|
        ds.with = 'boxes'
        ds.title = opts[:x_label]
        ds.using = '($1):(1.0)'
        ds.smooth = 'freq'
      end
    end
  end 
end

.plot_html(x, opts) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/grada/types/histogram.rb', line 31

def self.plot_html(x, opts)
  opts[:filename] = create_html_dir(opts[:filename])

  create_grada_json(opts, x)

  File.open("#{opts[:filename]}.html",'w') do |f|
    f << html_head
    f << "<body>\n"
    f << "  <div class=grada_main>\n"
    f << html_title(opts[:title])
    f << html_graph
    f << html_panel
    f << "  </div>"
    f << "</body>"
  end
end