| Class | GNUPlotter |
| In: |
lib/gnu_plotter.rb
|
| Parent: | Object |
| FONT | = | "/Library/Fonts/Arial.ttf" | Default font face. | |
| FONT_SIZE | = | 28 | Default font size. | |
| FS_MIN | = | 11 | Default minimum jitter font size. | |
| FS_MAX | = | 48 | Default maximum jitter font size. | |
| JITTER_MAX | = | 0.2 | Default location jitter max. | |
| JITTER_RANGE | = | 0.5 | Default location jitter if percent differrence less than this value | |
| WIDTH | = | 800 | Default plot width. | |
| HEIGHT | = | 600 | Default plot height. | |
| FILE_NAME | = | 'plot' | Default file name. | |
| FILE_TYPE | = | 'png' | Default file type. |
Create a GNU plot.
options::font the font to use if not default.
options::font_size the font size to use if not default
options::data the plot data as a value passable to Gnuplot::DataSet.new (e.g. an Array).
options::file_name the file name. Defaults to ‘plot’.
options::file_type the file type. Default to ‘png’.
options::title the graph title.
options::xlabel the x-axis labels.
options::ylabel the y-axis labels.
options::size the size of the graph as a [width, height] array. Defaults to [800, 600]
options::logscale if passed the logscale string. You cannot pass a yrange if a logscale is passed.
options::yrange if passed the y-range as a [min, max] array. You cannot pass a logscale if a yrange is passed.
options::xrange if passed the x-range as a [min, max] array.
options::xtics if passed the xtics as an array of labels.
options::ytics if passed the xtics as an array of labels.
# File lib/gnu_plotter.rb, line 80
80: def plot(options = {}, &blk)
81: Gnuplot.open do |gp|
82: Gnuplot::Plot.new( gp ) do |plot|
83: plot, data = assign_options(plot, options)
84: plot.boxwidth 0.5
85: yield(plot) unless blk.nil?
86: plot.data << Gnuplot::DataSet.new(data) do |ds|
87: ds.notitle
88: ds.with = "boxes fs solid 1"
89: end
90: end
91: end
92: end
Create a thermometer plot.
| options: | the plot options. |
options::data The therm data should be formatted as a set of column arrays. Each column array must be an array of triple the first member being the title to jitter, the second the y-position of that title, and the third the scale size of that title.
# File lib/gnu_plotter.rb, line 33
33: def therm_plot(options = {})
34: options[:xtics].push("") if options[:xtics]
35: data = options[:data]
36: percents = data.flatten.every(3, 1)
37: options[:yrange] = [percents.min, percents.max] unless options[:yrange]
38: options[:data] = Array.new(data.length + 1, 0)
39: plot(options) do |plot|
40: count = 0
41: data.each do |values|
42: values.each do |title, percent, votes|
43: plot.label "\"#{title.gsub(/\W/, ' ')}\" at first #{jitter(count, percent, values.transpose[1])}, first #{percent} font \"#{FONT},#{font_scale(values.transpose.last, votes)})\""
44: end
45: count += 1
46: end
47: end
48: end