rdp / ruby_gnuplot

The ruby gnuplot gem [gnuplot] [rgnuplot] (official releases of the gnuplot gem are from rdp branch)
BSD 3-Clause "New" or "Revised" License
217 stars 48 forks source link

Outputting plot data to stdout #26

Open maasha opened 10 years ago

maasha commented 10 years ago

Hello

I would like this script to output nice ASCII formatted plot data via the 'dumb' terminal to STDOUT, but I can't find a way? In fact, it could also be nice to allow output of raw PNG, PS and PDF data to STDOUT.

#!/usr/bin/env ruby

require 'gnuplot'
require 'pp'

# options = {
#   terminal: "png",
#   title: "Title",
#   xlabel: "X-axis",
#   ylabel: "Y-axis",
#   data_out: "foo.png"
# }

options = {
  terminal: "dumb",
  title: "Title",
  xlabel: "X-axis",
  ylabel: "Y-axis"
}

x = [0, 1, 2, 3]
y = [4, 5, 6, 7]

Gnuplot.open do |gp|
  Gnuplot::Plot.new(gp) do |plot|
    plot.terminal options[:terminal]
    plot.title    options[:title]
    plot.xlabel   options[:xlabel]
    plot.ylabel   options[:ylabel]
    plot.output   options[:data_out] if options[:data_out]
    plot.output   options[:data_out] if options[:data_out]
    plot.logscale "y"                if options[:logscale_y]
    plot.xrange   "[#{x.min - 1}:#{x.max + 1}]"
    plot.style    "fill solid 0.5 border"
    plot.xtics    "out"
    plot.ytics    "out"

    plot.data << Gnuplot::DataSet.new([x, y]) do |ds|
      ds.with = "boxes"
      ds.notitle
    end
  end
end