gnuplotr 0.1 → 0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +42 -6
- data/lib/gnuplotr.rb +25 -1
- data/test.rb +21 -5
- metadata +2 -2
data/README.markdown
CHANGED
@@ -11,24 +11,60 @@ Here's a quick example:
|
|
11
11
|
# Instantiate
|
12
12
|
gp = GNUPlotr.new
|
13
13
|
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
# fill the series with pairs. This creates the parabola.dat file
|
14
|
+
# Create and fill a new series with pairs. This creates the parabola.dat file
|
15
|
+
# Block-based way to do it:
|
18
16
|
gp.fill_series(:parabola) do |series|
|
19
17
|
(0..99).each do |i|
|
20
18
|
series << [i, i**2]
|
21
19
|
end
|
22
20
|
end
|
23
21
|
|
22
|
+
# conventional way:
|
23
|
+
gp.new_series(:parabola_2)
|
24
|
+
(0..99).each do |i|
|
25
|
+
gp.series[:parabola_2] << [i, i**2]
|
26
|
+
end
|
27
|
+
gp.series[:parabola_2].close # Remember to call this!
|
28
|
+
|
29
|
+
|
24
30
|
# enable command history recording
|
25
31
|
gp.record = true
|
26
32
|
|
33
|
+
# Issue raw gnuplot commands
|
34
|
+
gp.raw "set grid"
|
35
|
+
|
36
|
+
# Some magic mapping works too:
|
37
|
+
gp.set_grid
|
38
|
+
gp.set_title 'GNUPlotr example'
|
39
|
+
gp.set_xlabel 'x', :offset => 3, :font => "Times New Roman,26"
|
40
|
+
gp.set_ylabel "f(x)"
|
41
|
+
|
27
42
|
# issue plotting commands, either with named data series
|
28
|
-
gp.plot :parabola, "using 1:2 with points"
|
43
|
+
gp.plot :parabola, "using 1:2 with points axes x1y1"
|
29
44
|
|
30
45
|
# or with formulas. Options are collected in a string passed as second optional argument
|
31
46
|
gp.replot "x**2", "with lines"
|
32
47
|
|
48
|
+
|
33
49
|
# command history can be dumper and possibly saved on file to be edited or loaded again later on.
|
34
|
-
puts gp.dump_input
|
50
|
+
puts gp.dump_input
|
51
|
+
|
52
|
+
Installation
|
53
|
+
------------
|
54
|
+
|
55
|
+
As usual, use the gem:
|
56
|
+
|
57
|
+
% [sudo] gem install gnuplotr
|
58
|
+
|
59
|
+
Needless to say, you probably have to install a GNUPlot version in order to use gnuplotr. At the moment, gnuplotr is not too smart in detecting your GNUPlot installation path: it simply assumes that you are on MAC OS X and that you installed it via port, so that the executable is on /opt/local/bin/gnuplot.
|
60
|
+
|
61
|
+
If that is not your case, you must specify GNUPlot path as argument when you instantiate gnuplotr:
|
62
|
+
|
63
|
+
gp = GNUPlotr.new("/path/to/your/gnuplot")
|
64
|
+
|
65
|
+
**Please Note**: on Mac OS X, it seems that GNUPlot fails plotting on AquaTerm the first time you use it. To overcome this problem, do like that:
|
66
|
+
|
67
|
+
1. launch GNUPlot in Terminal and type some plotting command (*e.g.* plot sin(x)). Most probably nothing will happen.
|
68
|
+
2. Manually launch AquaTerm (it is in Applications)
|
69
|
+
3. Exit GNUPlot and launch it again, then try again to plot. Now it should work fine.
|
70
|
+
4. From now on, gnuplotr should work fine too, and you even don't need to pre-launch AquaTerm (it will open automatically).
|
data/lib/gnuplotr.rb
CHANGED
@@ -49,9 +49,17 @@ class GNUPlotr
|
|
49
49
|
|
50
50
|
def fill_series(name)
|
51
51
|
raise "Need a block" unless block_given?
|
52
|
+
new_series(name) unless @series[name]
|
52
53
|
yield @series[name]
|
53
54
|
@series[name].close
|
54
55
|
end
|
56
|
+
|
57
|
+
def method_missing(name, *args, &block)
|
58
|
+
options = args.inject("") {|s, t|
|
59
|
+
s + " " + parse_tokens(t)
|
60
|
+
}
|
61
|
+
raw "#{name.to_s.sub(/_/, " ")} #{options}"
|
62
|
+
end
|
55
63
|
|
56
64
|
def raw(message)
|
57
65
|
@record_list << message if @record
|
@@ -93,13 +101,29 @@ class GNUPlotr
|
|
93
101
|
yield line if line =~ /^\s*\w+/
|
94
102
|
end
|
95
103
|
end
|
104
|
+
|
105
|
+
def parse_tokens(t)
|
106
|
+
case t
|
107
|
+
when Symbol
|
108
|
+
t.to_s
|
109
|
+
when String
|
110
|
+
"'#{t}'"
|
111
|
+
when Hash
|
112
|
+
r = ""
|
113
|
+
t.each {|k,v|
|
114
|
+
r += " #{k.to_s} #{parse_tokens(v)}"
|
115
|
+
}
|
116
|
+
r
|
117
|
+
else
|
118
|
+
t.to_s
|
119
|
+
end
|
120
|
+
end
|
96
121
|
end
|
97
122
|
|
98
123
|
|
99
124
|
|
100
125
|
if $0 == __FILE__
|
101
126
|
gp = GNUPlotr.new
|
102
|
-
gp.new_series :parabola
|
103
127
|
gp.fill_series(:parabola) do |s|
|
104
128
|
(0..99).each do |i|
|
105
129
|
s << [i, i**2]
|
data/test.rb
CHANGED
@@ -9,24 +9,40 @@ require './lib/gnuplotr'
|
|
9
9
|
# Instantiate
|
10
10
|
gp = GNUPlotr.new
|
11
11
|
|
12
|
-
#
|
13
|
-
|
14
|
-
|
15
|
-
# fill the series with pairs. This creates the parabola.dat file
|
12
|
+
# Create and fill a new series with pairs. This creates the parabola.dat file
|
13
|
+
# Block-based way to do it:
|
16
14
|
gp.fill_series(:parabola) do |series|
|
17
15
|
(0..99).each do |i|
|
18
16
|
series << [i, i**2]
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
20
|
+
# conventional way:
|
21
|
+
gp.new_series(:parabola_2)
|
22
|
+
(0..99).each do |i|
|
23
|
+
gp.series[:parabola_2] << [i, i**2]
|
24
|
+
end
|
25
|
+
gp.series[:parabola_2].close # Remember to call this!
|
26
|
+
|
27
|
+
|
22
28
|
# enable command history recording
|
23
29
|
gp.record = true
|
24
30
|
|
31
|
+
# Issue raw gnuplot commands
|
32
|
+
gp.raw "set grid"
|
33
|
+
|
34
|
+
# Some magic mapping works too:
|
35
|
+
gp.set_grid
|
36
|
+
gp.set_title 'GNUPlotr example'
|
37
|
+
gp.set_xlabel 'x', :offset => 3, :font => "Times New Roman,26"
|
38
|
+
gp.set_ylabel "f(x)"
|
39
|
+
|
25
40
|
# issue plotting commands, either with named data series
|
26
|
-
gp.plot :parabola, "using 1:2 with points"
|
41
|
+
gp.plot :parabola, "using 1:2 with points axes x1y1"
|
27
42
|
|
28
43
|
# or with formulas. Options are collected in a string passed as second optional argument
|
29
44
|
gp.replot "x**2", "with lines"
|
30
45
|
|
46
|
+
|
31
47
|
# command history can be dumper and possibly saved on file to be edited or loaded again later on.
|
32
48
|
puts gp.dump_input
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gnuplotr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: "0.
|
5
|
+
version: "0.2"
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Paolo Bosetti
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-24 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|