Class: ScbiPlot::Histogram
Instance Attribute Summary
Attributes inherited from Plot
#file_name, #line_width, #title, #x, #x_label, #x_limit, #x_range, #y, #y2_label, #y2_range, #y_label, #y_range
Instance Method Summary collapse
- #do_graph ⇒ Object
-
#initialize(file_name, title = nil) ⇒ Histogram
constructor
A new instance of Histogram.
Methods inherited from Plot
#add_x, #add_xy, #add_y, #check_data_limit, #contains_strings?, #gnu_plot_installed?, #setup_data, #which, #xy_to_hash
Constructor Details
#initialize(file_name, title = nil) ⇒ Histogram
Returns a new instance of Histogram.
26 27 28 29 30 |
# File 'lib/scbi_plot/histogram.rb', line 26 def initialize(file_name,title=nil) super @line_width=4 @show_leyend=false end |
Instance Method Details
#do_graph ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/scbi_plot/histogram.rb', line 32 def do_graph setup_data # $VERBOSE=false if !gnu_plot_installed? puts "GNUPLOT executable not installed" return end Gnuplot.open do |gp| # histogram Gnuplot::Plot.new( gp ) do |plot| if !title title=file_name end plot.title "#{@title}" plot.xlabel @x_label plot.ylabel @y_label if !@show_leyend plot.set "key off" #leyend end # x values are integers if !contains_strings?(@x) if @x_range.empty? if @x.min==@x.max @x.first.class # puts "MISMO MIN MAX" xrange="[#{@x.min-1}:#{@x.max+1}]" else xrange="[#{@x.min}:#{@x.max}]" end plot.xrange xrange plot.x2range xrange else plot.xrange @x_range plot.x2range @x_range end if !@y_range.empty? plot.yrange @y_range end plot.style "fill pattern 22 border -1" plot.set "boxwidth 0.2" # Probably 3-5. plot.data << Gnuplot::DataSet.new( [@x, @y] ) do |ds| ds.with= " imp lw #{@line_width}" end else #graph with strings in X axis # $VERBOSE=true plot.xlabel "" plot.set "style fill solid 1.00 border -1" plot.set "style histogram clustered gap 1 title offset character 0, 0, 0" plot.set "style data histogram" plot.set "boxwidth 0.2 absolute" if @x.count>4 then plot.set "xtics offset 0,graph 0 rotate 90" end plot.data << Gnuplot::DataSet.new( [@x,@y] ) do |ds| ds.using = "2:xticlabels(1)" #show the graph and use labels at x end end if !file_name.nil? plot.terminal "png size 800,600" plot.output "#{@file_name}" end end end end |