File: gnuplot.rb

package info (click to toggle)
ruby-gsl 1.14.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 5,116 kB
  • sloc: ansic: 62,186; ruby: 17,804; makefile: 18; sh: 15
file content (38 lines) | stat: -rwxr-xr-x 677 bytes parent folder | download | duplicates (3)
1
2
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
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby
# Turn on warnings
$-w = true

require 'gnuplot'
require 'gsl'
require 'gsl/gnuplot';

# Plot using gnuplot
Gnuplot.open do |gp|
  Gnuplot::Plot.new( gp ) do |plot|
  
    plot.xrange "[0:10]"
    plot.yrange "[-1.5:1.5]"
    plot.title  "Sin Wave Example"
    plot.xlabel "x"
    plot.ylabel "sin(x)"
    plot.pointsize 3
    plot.grid 

    x = GSL::Vector[0..10]
    y = GSL::Sf::sin(x)

    plot.data = [
      Gnuplot::DataSet.new( "sin(x)" ) { |ds|
	ds.with = "lines"
	ds.title = "String function"
	ds.linewidth = 4
      },
      
      Gnuplot::DataSet.new( [x, y] ) { |ds|
	ds.with = "linespoints"
	ds.title = "Array data"
      }
    ]

  end
end