gnuplot 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3 -0
- data/README.textile +35 -50
- data/Rakefile +1 -1
- data/lib/gnuplot.rb +20 -8
- data/test/test_gnuplot.rb +15 -3
- metadata +2 -2
data/ChangeLog
CHANGED
data/README.textile
CHANGED
@@ -25,60 +25,57 @@ h2. Ruby Gnuplot Concepts
|
|
25
25
|
|
26
26
|
|
27
27
|
The object model for the Ruby gnuplot wrapper directly mimics this
|
28
|
-
layout and flow.
|
28
|
+
layout and flow. The following are the standard steps for generating a
|
29
29
|
plot:
|
30
30
|
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
the plot command using the modifier name.
|
32
|
+
# Instantiate a @Plot@ or @Splot@ object and set parameters by gnuplot variable name.
|
33
|
+
|
34
|
+
# Instantiate @DataSet@ objects and attach Ruby objects containing the data to be plotted to the @DataSet@. Attach properties that modify the plot command using the modifier name.
|
36
35
|
|
37
|
-
|
38
|
-
plotting.
|
36
|
+
# Send the @Plot@/@Splot@ object to a @Gnuplot@ instance for plotting.
|
39
37
|
|
40
38
|
The Version 2.0 interface makes very heavy use of blocks leading to very
|
41
39
|
readable code.
|
42
40
|
|
43
|
-
Gnuplot.open
|
44
|
-
|
41
|
+
@Gnuplot.open@
|
45
42
|
|
46
43
|
bq.
|
47
|
-
Instantiates a new Gnuplot process.
|
44
|
+
Instantiates a new Gnuplot process. The path to the executable is
|
48
45
|
determined on a Unix or MacOSX system using the which command. Windows
|
49
46
|
users, I have no idea what to do.
|
50
47
|
If a block is given to the function the opened process is passed into
|
51
|
-
the block.
|
48
|
+
the block. This mimics the most common usage of the @File.open@ method.
|
52
49
|
|
53
|
-
Plot.new
|
50
|
+
@Plot.new@
|
54
51
|
|
55
52
|
|
56
|
-
SPlot.new
|
53
|
+
@SPlot.new@
|
57
54
|
|
58
55
|
bq.
|
59
|
-
Create a new Plot or
|
56
|
+
Create a new @Plot@ or @SPlot@ object. @DataSet@ s are attached to the object
|
60
57
|
to specify the data and its properties.
|
61
58
|
If a block is given to the function, the plot object is passed into the
|
62
59
|
block.
|
63
60
|
|
64
|
-
DataSet.new
|
61
|
+
@DataSet.new@
|
65
62
|
|
66
63
|
bq.
|
67
64
|
Associates a Ruby object containing the data to plot with the properties
|
68
|
-
that will be passed to the plot command for that dataset.
|
69
|
-
object can be associated with a DataSet as long as it understands the
|
70
|
-
to_gplot method.
|
65
|
+
that will be passed to the plot command for that dataset. Any Ruby
|
66
|
+
object can be associated with a @DataSet@ as long as it understands the
|
67
|
+
@to_gplot@ method.
|
71
68
|
|
72
|
-
|
69
|
+
@to_gplot@
|
73
70
|
|
74
71
|
bq.
|
75
72
|
Within Gnuplot, plot data is read in very simple formats. The
|
76
|
-
to_gplot method is expected to write the data of the object in a format
|
77
|
-
that is understandable by Gnuplot.
|
78
|
-
Ruby is that methods can be added after the original declaration.
|
79
|
-
gnuplot module defines the to_gplot method on the following classes:
|
80
|
-
Array
|
81
|
-
Simply define a to_gplot method on your own class to tie the class into
|
73
|
+
@to_gplot@ method is expected to write the data of the object in a format
|
74
|
+
that is understandable by Gnuplot. One of the many great things about
|
75
|
+
Ruby is that methods can be added after the original declaration. The
|
76
|
+
gnuplot module defines the @to_gplot@ method on the following classes:
|
77
|
+
@Array@, @String@, and @Matrix@.
|
78
|
+
Simply define a @to_gplot@ method on your own class to tie the class into
|
82
79
|
gnuplot.
|
83
80
|
|
84
81
|
h2. Examples
|
@@ -89,26 +86,13 @@ h3. Simple sin wave
|
|
89
86
|
bq. The following example simply plots the value of sin(x) between the
|
90
87
|
ranges of -10 and 10. A few points to notice:
|
91
88
|
|
92
|
-
|
93
|
-
created object is passed to the block so it can be modified in
|
94
|
-
place.
|
89
|
+
* The code uses nested blocks to construct the plot. The newly created object is passed to the block so it can be modified in place.
|
95
90
|
|
96
|
-
|
97
|
-
variable name as a method name on the plot object or on the dataset
|
98
|
-
object. The wrapper also takes care of the single quoting that is
|
99
|
-
required on some of the variables like title, ylabel, and xlabel.
|
100
|
-
|
91
|
+
* Each of the gnuplot plot variables are modified using the variable name as a method name on the plot object or on the dataset object. The wrapper also takes care of the single quoting that is required on some of the variables like @title@, @ylabel@, and @xlabel@.
|
101
92
|
|
102
|
-
|
103
|
-
constructor initializes this empty array before yielding to the
|
104
|
-
block. This method uses the << operator to add the DataSet to
|
105
|
-
the plot.
|
106
|
-
|
93
|
+
* The plot object simply has an array of @DataSet@s. The constructor initializes this empty array before yielding to the block. This method uses the @<<@ operator to add the @DataSet@ to the plot.
|
107
94
|
|
108
|
-
|
109
|
-
constructor, the plot commands will be written to the IO object.
|
110
|
-
Any object can be passed to the constructor as long as it
|
111
|
-
understands the << operator.
|
95
|
+
* When the plot block ends, if an @IO@ object is given to the @Plot@ constructor, the plot commands will be written to the @IO@ object. Any object can be passed to the constructor as long as it understands the @<<@ operator.
|
112
96
|
|
113
97
|
<pre>
|
114
98
|
Gnuplot.open do |gp|
|
@@ -130,21 +114,22 @@ end
|
|
130
114
|
</pre>
|
131
115
|
|
132
116
|
Or you can write it out to a file (the above snippet displays the graph, in Linux, but in windows you'd need to write it to a file).
|
133
|
-
|
117
|
+
|
118
|
+
See the file @examples/output_image_file.rb@.
|
134
119
|
|
135
120
|
h3. Plotting discrete points
|
136
121
|
|
137
|
-
Array data can be plotted quite easily since
|
122
|
+
Array data can be plotted quite easily since @Array@s have a defined @to_gplot@ method.
|
138
123
|
|
139
|
-
Simply pass an array of data to the constructor of the DataSet object or set the data property of the DataSet
|
124
|
+
Simply pass an array of data to the constructor of the @DataSet@ object or set the data property of the @DataSet@. In this example, because there are two arrays, each array will be a single column of data to the gnuplot process.
|
140
125
|
|
141
126
|
<pre>
|
142
127
|
Gnuplot.open do |gp|
|
143
128
|
Gnuplot::Plot.new( gp ) do |plot|
|
144
129
|
|
145
130
|
plot.title "Array Plot Example"
|
146
|
-
plot.
|
147
|
-
plot.
|
131
|
+
plot.xlabel "x"
|
132
|
+
plot.ylabel "x^2"
|
148
133
|
|
149
134
|
x = (0..50).collect { |v| v.to_f }
|
150
135
|
y = x.collect { |v| v ** 2 }
|
@@ -159,9 +144,9 @@ end
|
|
159
144
|
|
160
145
|
h3. Multiple Data Sets
|
161
146
|
|
162
|
-
As many data sets as are desired can be attached to a plot. Each of these can have their own plot modifiers. Notice in this example how the data array is explicitly set instead of using the
|
147
|
+
As many data sets as are desired can be attached to a plot. Each of these can have their own plot modifiers. Notice in this example how the data array is explicitly set instead of using the @<<@ operator.
|
163
148
|
|
164
|
-
Also in this example, the commands are not written to the Gnuplot process but are instead written to a File called gnuplot.dat
|
149
|
+
Also in this example, the commands are not written to the Gnuplot process but are instead written to a File called @gnuplot.dat@. This file can later be run directly by a gnuplot process as it contains only the gnuplot commands.
|
165
150
|
|
166
151
|
<pre>
|
167
152
|
File.open( "gnuplot.dat", "w") do |gp|
|
@@ -199,4 +184,4 @@ plot.arbitrary_lines << "set ylabel \"y label" font \"Helvetica,20\""
|
|
199
184
|
</pre>
|
200
185
|
|
201
186
|
See more in the examples folder. Also since this is basically just a wrapper for gnuplot itself, you should be able to do anything that it can do (demos:
|
202
|
-
http://gnuplot.sourceforge.net/demo_4.4/ )
|
187
|
+
http://gnuplot.sourceforge.net/demo_4.4/ )
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'jeweler2'
|
|
2
2
|
Jeweler::Tasks.new do |s|
|
3
3
|
s.name = 'gnuplot'
|
4
4
|
s.description = s.summary = "Utility library to aid in interacting with gnuplot from ruby"
|
5
|
-
s.version = "2.
|
5
|
+
s.version = "2.6.0"
|
6
6
|
s.authors='roger pack'
|
7
7
|
s.email = "rogerpack2005@gmail.com"
|
8
8
|
s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master"
|
data/lib/gnuplot.rb
CHANGED
@@ -88,13 +88,13 @@ module Gnuplot
|
|
88
88
|
# object set the various properties and add data sets.
|
89
89
|
|
90
90
|
class Plot
|
91
|
-
attr_accessor :cmd, :data, :
|
91
|
+
attr_accessor :cmd, :data, :settings
|
92
92
|
|
93
93
|
QUOTED = [ "title", "output", "xlabel", "x2label", "ylabel", "y2label", "clabel", "cblabel", "zlabel" ]
|
94
94
|
|
95
95
|
def initialize (io = nil, cmd = "plot")
|
96
96
|
@cmd = cmd
|
97
|
-
@
|
97
|
+
@settings = []
|
98
98
|
@arbitrary_lines = []
|
99
99
|
@data = []
|
100
100
|
yield self if block_given?
|
@@ -125,7 +125,12 @@ module Gnuplot
|
|
125
125
|
|
126
126
|
def set ( var, value = "" )
|
127
127
|
value = "\"#{value}\"" if QUOTED.include? var unless value =~ /^'.*'$/
|
128
|
-
@
|
128
|
+
@settings << [ :set, var, value ]
|
129
|
+
end
|
130
|
+
|
131
|
+
# Unset a variable. +Var+ must be a gnuplot variable.
|
132
|
+
def unset ( var )
|
133
|
+
@settings << [ :unset, var ]
|
129
134
|
end
|
130
135
|
|
131
136
|
|
@@ -134,8 +139,12 @@ module Gnuplot
|
|
134
139
|
# gnuplot process.
|
135
140
|
|
136
141
|
def [] ( var )
|
137
|
-
v = @
|
138
|
-
v
|
142
|
+
v = @settings.rassoc( var )
|
143
|
+
if v.nil? or v.first == :unset
|
144
|
+
nil
|
145
|
+
else
|
146
|
+
v[2]
|
147
|
+
end
|
139
148
|
end
|
140
149
|
|
141
150
|
|
@@ -145,7 +154,9 @@ module Gnuplot
|
|
145
154
|
|
146
155
|
|
147
156
|
def to_gplot (io = "")
|
148
|
-
@
|
157
|
+
@settings.each do |setting|
|
158
|
+
io << setting.map(&:to_s).join(" ") << "\n"
|
159
|
+
end
|
149
160
|
@arbitrary_lines.each{|line| io << line << "\n" }
|
150
161
|
|
151
162
|
io
|
@@ -195,11 +206,11 @@ module Gnuplot
|
|
195
206
|
# @todo Use the delegator to delegate to the data property.
|
196
207
|
|
197
208
|
class DataSet
|
198
|
-
attr_accessor :title, :with, :using, :data, :linewidth, :matrix, :smooth, :axes
|
209
|
+
attr_accessor :title, :with, :using, :data, :linewidth, :linecolor, :matrix, :smooth, :axes
|
199
210
|
|
200
211
|
def initialize (data = nil)
|
201
212
|
@data = data
|
202
|
-
@title = @with = @using = @linewidth = @matrix = @smooth = @axes = nil # avoid warnings
|
213
|
+
@title = @with = @using = @linewidth = @linecolor = @matrix = @smooth = @axes = nil # avoid warnings
|
203
214
|
yield self if block_given?
|
204
215
|
end
|
205
216
|
|
@@ -226,6 +237,7 @@ module Gnuplot
|
|
226
237
|
io << " matrix" if @matrix
|
227
238
|
io << " smooth #{@smooth}" if @smooth
|
228
239
|
io << " with #{@with}" if @with
|
240
|
+
io << " linecolor #{@linecolor}" if @linecolor
|
229
241
|
io << " linewidth #{@linewidth}" if @linewidth
|
230
242
|
io
|
231
243
|
end
|
data/test/test_gnuplot.rb
CHANGED
@@ -56,11 +56,13 @@ class PlotTest < Test::Unit::TestCase
|
|
56
56
|
plot = Gnuplot::Plot.new do |p|
|
57
57
|
p.set "output", "'foo'"
|
58
58
|
p.set "terminal", "postscript enhanced"
|
59
|
+
p.unset "border"
|
59
60
|
end
|
60
61
|
|
61
|
-
assert( plot.
|
62
|
-
[ ["output", "'foo'"],
|
63
|
-
["terminal", "postscript enhanced"]
|
62
|
+
assert( plot.settings ==
|
63
|
+
[ [:set, "output", "'foo'"],
|
64
|
+
[:set, "terminal", "postscript enhanced"],
|
65
|
+
[:unset, "border"] ] )
|
64
66
|
|
65
67
|
|
66
68
|
assert( plot.to_gplot, \
|
@@ -78,6 +80,16 @@ class PlotTest < Test::Unit::TestCase
|
|
78
80
|
assert "'foo'", plot["title"]
|
79
81
|
end
|
80
82
|
|
83
|
+
def test_unset
|
84
|
+
plot = Gnuplot::Plot.new do |p|
|
85
|
+
p.unset "title"
|
86
|
+
end
|
87
|
+
assert_nil plot["title"]
|
88
|
+
|
89
|
+
plot.unset "title"
|
90
|
+
assert_nil plot["title"]
|
91
|
+
end
|
92
|
+
|
81
93
|
end
|
82
94
|
|
83
95
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gnuplot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Utility library to aid in interacting with gnuplot from ruby
|
15
15
|
email: rogerpack2005@gmail.com
|