Class: EvoSynth::Output::GnuPlotExporter
- Inherits:
-
Object
- Object
- EvoSynth::Output::GnuPlotExporter
- Defined in:
- lib/evosynth/output/exporter/gnuplot_exporter.rb
Overview
exports the contents (data) of a logger to gnuplot
Instance Method Summary collapse
- #export(title) ⇒ Object
-
#initialize(logger) ⇒ GnuPlotExporter
constructor
A new instance of GnuPlotExporter.
Constructor Details
#initialize(logger) ⇒ GnuPlotExporter
35 36 37 38 39 40 41 42 43 |
# File 'lib/evosynth/output/exporter/gnuplot_exporter.rb', line 35 def initialize(logger) begin require 'gnuplot' rescue puts "Could not require 'gnuplot' gem, please install with gem install gnuplot" end @logger = logger end |
Instance Method Details
#export(title) ⇒ Object
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 |
# File 'lib/evosynth/output/exporter/gnuplot_exporter.rb', line 45 def export(title) begin Gnuplot.open do |gp| Gnuplot::Plot.new( gp ) do |plot| plot.title title # plot.ylabel "fitness" # plot.xlabel "generation" x, ys = [], [] data_sets = 0 @logger.data.each_pair do |key, value| data_sets = value.size if value.size > data_sets x << key value.each_with_index do |y, index| ys[index] = [] if ys[index].nil? ys[index] << y end end data_sets.times do |set| plot.data << Gnuplot::DataSet.new( [x, ys[set]] ) do |ds| ds.with = "lines" ds.title = @logger.column_names[set] end end end end rescue puts "Could not run gnuplot - have you gnuplot installed? It does not work on windows yet!" end end |