gnuplot 2.3.3 → 2.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS.txt ADDED
@@ -0,0 +1,5 @@
1
+ Gordon James Miller
2
+ Ara T. Howard
3
+ Roger Pack
4
+ Mike Cahill (minor edits)
5
+ jakobs
data/ChangeLog ADDED
@@ -0,0 +1,51 @@
1
+ 2.3.4
2
+ * Include more files in the gem by switching to Jeweler (thanks Jeweler guyz)!
3
+
4
+ 2.3.3
5
+ * Fix issue #4 (thanks Jakobs)
6
+ * Fix some unit tests (thanks Nobu!)
7
+
8
+ 2.3.2 Feb 2010
9
+ * Add an arbitrary_lines specifier
10
+
11
+ 2.3.1 Feb 2010
12
+
13
+ * Fix a bug I introduced in 2.3.0
14
+
15
+ 2.3.0 Feb 2010
16
+
17
+ * incorporate a few patch changes
18
+
19
+ 2.2.3.1 July 18 2009
20
+
21
+ * output the raw "to gnuplot" data if $VERBOSE
22
+
23
+ Version 2.2.2 July 2009
24
+
25
+ * raise if no executable found, should be windows compat. now
26
+
27
+ Version 2.2 14-Nov-2005
28
+
29
+ * Formally added the LICENSE.txt file. It is the new BSD license as defined
30
+ by opensource.org. See that file for details.
31
+
32
+ * Added Gnuplot.which to try and fix the recurring problem of windows users
33
+ having to hack code to get things working.
34
+
35
+ * Added the Gnuplot.gnuplot function so that I can unit test the finding
36
+ gnuplot executable routine.
37
+
38
+ * In the Array.to_gplot method the terminating e is added to the output. This
39
+ is in response to Bug #2209.
40
+
41
+ Version 2.1 17-Nov-2004
42
+
43
+ * Array.to_gplot and Array.to_gsplot now support passing in arrays of
44
+ arbitrary objects. This is in response to a request by Yoshiki Tsunesada
45
+ (Tracker ID 1063)
46
+
47
+ Version 2.0 10-Nov-2004
48
+
49
+ * The 2.0 version of the gnuplot interface is a cross between the original,
50
+ object oriented version, and the version 1.0 which was simply a string
51
+ manipulation library.
data/LICENSE.txt ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2004-2005, Gordon James Miller (gmiller@bittwiddlers.com)
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the BitTwiddlers, Inc. nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.textile ADDED
@@ -0,0 +1,234 @@
1
+ h1. Ruby Gnuplot - How To
2
+
3
+ p=.
4
+ ["Rubyforge Project
5
+ page":http://rubyforge.org/projects/rgplot]
6
+ ["ChangeLog":ChangeLog]
7
+ ["Authors":AUTHORS.txt]
8
+ ["License":LICENSE.txt]
9
+
10
+ h2. History and Background
11
+
12
+ Gnuplot is a program that has a rich language for the generation of
13
+ plots. It has a unique place in academia as it was one of the first
14
+ freely available programs for plot generation. I started using gnuplot
15
+ over 10 years ago while pursuing my Master's degree in Physics and have
16
+ been using it actively ever since.
17
+
18
+ h3. Version 0.9
19
+
20
+ bq.
21
+ My first attempt at a Ruby interface to gnuplot was an object interface
22
+ encapsulating gnuplot language. This was taken directly from the Python
23
+ gnuplot interface. In spite of my being very familiar with Gnuplot and
24
+ Ruby and being the author of the RGnuplot package, I found it
25
+ non-intuitive to use the RGnuplot package. I found myself constantly
26
+ looking at the code to figure out what I needed to do.
27
+ This was not sufficient and did not sit well.
28
+
29
+ h3. Version 1.0
30
+
31
+ bq.
32
+ The second attempt at a Ruby interface was to do absolutely nothing but
33
+ use Ruby's built in string manipulation methods. This meant that I
34
+ could simply use my knowledge of Gnuplot without having to worry about
35
+ objects.
36
+ While in some ways an improvement over Version 0.9, it still did not sit
37
+ well with me.
38
+
39
+ h3. Version 2.0
40
+
41
+ bq.
42
+ After attending RubyConf 2004 I was inspired by Rich Kilmer's use of
43
+ Ruby to implement domain specific languages. That is the current
44
+ implementation of Gnuplot and quite probably the one that I'll stick
45
+ with for some time. This version combines the direct mapping of the
46
+ gnuplot language without wrapping with the ruby syntax and mechanism of
47
+ adding methods to existing classes to interface Ruby objects with
48
+ gnuplot.
49
+
50
+ h2. Setup
51
+
52
+ h3. Version 2.2
53
+
54
+ If the 'gnuplot' command is in your path then there is no required
55
+ setup. If the gnuplot executable for your system is called something other
56
+ than simply 'gnuplot' then set the RB_GNUPLOT environment variable to the
57
+ name of the executable. This must either be a full path to the gnuplot
58
+ command or an executable filename that exists in your PATH environment
59
+ variable.
60
+
61
+ h2. Ruby Gnuplot Concepts
62
+
63
+ Gnuplot has a very simple conceptual model. Calls to _Set_ are
64
+ made to set parameters and either _Plot_ or _Splot_ is
65
+ called to generate the actual plot. The _dataset_ to be
66
+ plotted can be specified in a number of ways, contained in a seperate
67
+ file, generated from a function, read from standard input, or read
68
+ immediately after the plot command.
69
+
70
+
71
+ The object model for the Ruby gnuplot wrapper directly mimics this
72
+ layout and flow. The following are the standard steps for generating a
73
+ plot:
74
+
75
+
76
+ p. Instantiate a Plot or Splot object and set parameters by gnuplot variable name.
77
+ p. Instantiate DataSet objects and attach Ruby objects containing
78
+ the data to be plotted to the DataSet. Attach properties that modify
79
+ the plot command using the modifier name.
80
+
81
+ p. Send the Plot/Splot object to a Gnuplot instance for
82
+ plotting.
83
+
84
+ The Version 2.0 interface makes very heavy use of blocks leading to very
85
+ readable code.
86
+
87
+ Gnuplot.open
88
+
89
+
90
+ Instantiates a new Gnuplot process. The path to the executable is
91
+ determined on a Unix or MacOSX system using the which command. Windows
92
+ users, I have no idea what to do.
93
+ If a block is given to the function the opened process is passed into
94
+ the block. This mimics the most common usage of the File.open method.
95
+
96
+ Plot.new
97
+
98
+
99
+
100
+ bq.
101
+ Create a new Plot or Splot object. DataSets are attached to the object
102
+ to specify the data and its properties.
103
+ If a block is given to the function, the plot object is passed into the
104
+ block.
105
+
106
+ DataSet.new
107
+
108
+ bq.
109
+ Associates a Ruby object containing the data to plot with the properties
110
+ that will be passed to the plot command for that dataset. Any Ruby
111
+ object can be associated with a DataSet as long as it understands the
112
+ to_gplot method.
113
+
114
+ to_gplot
115
+
116
+ bq.
117
+ Within Gnuplot, plot data is read in very simple formats. The
118
+ to_gplot method is expected to write the data of the object in a format
119
+ that is understandable by Gnuplot. One of the many great things about
120
+ Ruby is that methods can be added after the original declaration. The
121
+ gnuplot module defines the to_gplot method on the following classes:
122
+ Array, String, and Matrix.
123
+ Simply define a to_gplot method on your own class to tie the class into
124
+ gnuplot.
125
+
126
+ h2. Examples
127
+
128
+
129
+
130
+ bq. The following example simply plots the value of sin(x) between the
131
+ ranges of -10 and 10. A few points to notice:
132
+
133
+
134
+ p. The code uses nested blocks to construct the plot. The newly
135
+ created object is passed to the block so it can be modified in
136
+ place.
137
+
138
+
139
+ p. Each of the gnuplot plot variables are modified using the
140
+ variable name as a method name on the plot object or on the dataset
141
+ object. The wrapper also takes care of the single quoting that is
142
+ required on some of the variables like title, ylabel, and xlabel.
143
+
144
+
145
+ p. The plot object simply has an array of DataSets. The
146
+ constructor initializes this empty array before yielding to the
147
+ block. This method uses the << operator to add the DataSet to
148
+ the plot.
149
+
150
+
151
+ p. When the plot block ends, if an IO object is given to the Plot
152
+ constructor, the plot commands will be written to the IO object.
153
+ Any object can be passed to the constructor as long as it
154
+ understands the << operator.
155
+
156
+ <pre><code>
157
+ Gnuplot.open do |gp|
158
+ Gnuplot::Plot.new( gp ) do |plot|
159
+
160
+ plot.xrange "[-10:10]"
161
+ plot.title "Sin Wave Example"
162
+ plot.ylabel "x"
163
+ plot.xlabel "sin(x)"
164
+
165
+ plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds|
166
+ ds.with = "lines"
167
+ ds.linewidth = 4
168
+ end
169
+
170
+ end
171
+
172
+ end
173
+
174
+
175
+
176
+ Array data can be plotted quite easily since Arrays have a defined to_gplot method.
177
+
178
+ 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.
179
+
180
+ Gnuplot.open do |gp|
181
+ Gnuplot::Plot.new( gp ) do |plot|
182
+
183
+ plot.title "Array Plot Example"
184
+ plot.ylabel "x"
185
+ plot.xlabel "x^2"
186
+
187
+ x = (0..50).collect { |v| v.to_f }
188
+ y = x.collect { |v| v ** 2 }
189
+
190
+ plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
191
+ ds.with = "linespoints"
192
+ ds.notitle
193
+ end
194
+ end
195
+ end
196
+
197
+ Multiple Data Sets
198
+
199
+ 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.
200
+
201
+ 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.
202
+
203
+ File.open( "gnuplot.dat", "w") do |gp|
204
+ Gnuplot::Plot.new( gp ) do |plot|
205
+
206
+ plot.xrange "[-10:10]"
207
+ plot.title "Sin Wave Example"
208
+ plot.ylabel "x"
209
+ plot.xlabel "sin(x)"
210
+
211
+ x = (0..50).collect { |v| v.to_f }
212
+ y = x.collect { |v| v ** 2 }
213
+
214
+ plot.data = [
215
+ Gnuplot::DataSet.new( "sin(x)" ) { |ds|
216
+ ds.with = "lines"
217
+ ds.title = "String function"
218
+ ds.linewidth = 4
219
+ },
220
+
221
+ Gnuplot::DataSet.new( [x, y] ) { |ds|
222
+ ds.with = "linespoints"
223
+ ds.title = "Array data"
224
+ }
225
+ ]
226
+
227
+ end
228
+
229
+ end
230
+
231
+
232
+ You can also add atribtrary lines to the output
233
+
234
+ plot.arbitrary_lines << "set ylabel \"y label" font \"Helvetica,20\""
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'jeweler'
2
+ Jeweler::Tasks.new do |s|
3
+ s.name = 'gnuplot'
4
+ s.description = s.summary = "Utility library to aid in interacting with gnuplot"
5
+ s.version = "2.3.4"
6
+ s.autorequire = 'gnuplot.rb'
7
+ s.email = "rogerpack2005@gmail.com"
8
+ s.homepage = "http://github.com/rdp/ruby_gnuplot/tree/master"
9
+ end
data/test/arrtest.rb ADDED
@@ -0,0 +1,21 @@
1
+ require '../lib/gnuplot'
2
+
3
+ Gnuplot.open do |gp|
4
+ Gnuplot::Plot.new( gp ) do |plot|
5
+
6
+ plot.title "Array Plot Example"
7
+ plot.ylabel "x"
8
+ plot.xlabel "x^2"
9
+
10
+ x = (0..50).collect { |v| v.to_f }
11
+ y = x.collect { |v| v ** 2 }
12
+
13
+ plot.data << Gnuplot::DataSet.new( [x, y] ) do |ds|
14
+ ds.with = "linespoints"
15
+ ds.notitle
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
data/test/histtest.rb ADDED
@@ -0,0 +1,20 @@
1
+ require '../lib/gnuplot'
2
+
3
+ Gnuplot.open do |gp|
4
+ gp << "bin(x, s) = s*int(x/s)\n"
5
+
6
+ Gnuplot::Plot.new( gp ) do |plot|
7
+ plot.title "Histogram"
8
+ plot.xlabel "x"
9
+ plot.ylabel "frequency"
10
+
11
+ x = (0..500).collect { |v| (rand()-0.5)**3 }
12
+ plot.data << Gnuplot::DataSet.new( [x] ) do |ds|
13
+ ds.title = "smooth frequency"
14
+ ds.using = "(bin($1,.01)):(1.)"
15
+ ds.smooth = "freq"
16
+ ds.with = "boxes"
17
+ end
18
+ end
19
+ end
20
+
data/test/multtest.rb ADDED
@@ -0,0 +1,31 @@
1
+ require '../lib/gnuplot'
2
+
3
+ # File.open( "gnuplot.dat", "w") do |gp|
4
+ Gnuplot.open do |gp|
5
+ Gnuplot::Plot.new( gp ) do |plot|
6
+
7
+ plot.xrange "[-10:10]"
8
+ plot.title "Sin Wave Example"
9
+ plot.ylabel "x"
10
+ plot.xlabel "sin(x)"
11
+
12
+ x = (0..50).collect { |v| v.to_f }
13
+ y = x.collect { |v| v ** 2 }
14
+
15
+ plot.data = [
16
+ Gnuplot::DataSet.new( "sin(x)" ) { |ds|
17
+ ds.with = "lines"
18
+ ds.title = "String function"
19
+ ds.linewidth = 4
20
+ },
21
+
22
+ Gnuplot::DataSet.new( [x, y] ) { |ds|
23
+ ds.with = "linespoints"
24
+ ds.title = "Array data"
25
+ }
26
+ ]
27
+
28
+ end
29
+
30
+ end
31
+
data/test/sinwave.rb ADDED
@@ -0,0 +1,19 @@
1
+ require '../lib/gnuplot'
2
+
3
+ Gnuplot.open do |gp|
4
+ Gnuplot::Plot.new( gp ) do |plot|
5
+
6
+ plot.xrange "[-10:10]"
7
+ plot.title "Sin Wave Example"
8
+ plot.ylabel "x"
9
+ plot.xlabel "sin(x)"
10
+
11
+ plot.data << Gnuplot::DataSet.new( "sin(x)" ) do |ds|
12
+ ds.with = "lines"
13
+ ds.linewidth = 4
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,120 @@
1
+ # -*- ruby -*-
2
+
3
+ require '../lib/gnuplot'
4
+ require 'test/unit'
5
+
6
+ class StdDataTest < Test::Unit::TestCase
7
+
8
+ def test_array_1d
9
+ data = (0..5).to_a
10
+ ds = Gnuplot::DataSet.new( data )
11
+
12
+ assert data == ds.data
13
+ assert data.join("\n") + "\n", ds.to_gplot
14
+ end
15
+
16
+
17
+ # Test a multidimensional array.
18
+
19
+ def test_array_nd
20
+ d1 = (0..3).to_a
21
+ d2 = d1.collect { |v| 3 * v }
22
+ d3 = d2.collect { |v| 4 * v }
23
+
24
+ data = [ d1, d2, d3 ]
25
+ ds = Gnuplot::DataSet.new( data )
26
+
27
+ assert data == ds.data
28
+ assert "0 0 0\n1 3 12\n2 6 24\n3 9 36\n", ds.to_gplot
29
+ end
30
+ end
31
+
32
+
33
+ class DataSetTest < Test::Unit::TestCase
34
+
35
+ def test_yield_ctor
36
+ ds = Gnuplot::DataSet.new do |ds|
37
+ ds.with = "lines"
38
+ ds.using = "1:2"
39
+ ds.data = [ [0, 1, 2], [1, 2, 5] ]
40
+ end
41
+
42
+ assert "lines", ds.with
43
+ assert "1:2", ds.using
44
+ assert nil == ds.title
45
+ assert [ [0, 1, 2], [1, 2, 5] ] == ds.data
46
+ assert "'-' using 1:2 with lines", ds.plot_args
47
+ assert "0 1\n1 2\n2 5\n", ds.to_gplot
48
+ end
49
+
50
+ end
51
+
52
+
53
+ class PlotTest < Test::Unit::TestCase
54
+
55
+ def test_no_data
56
+ plot = Gnuplot::Plot.new do |p|
57
+ p.set "output", "'foo'"
58
+ p.set "terminal", "postscript enhanced"
59
+ end
60
+
61
+ assert( plot.sets ==
62
+ [ ["output", "'foo'"],
63
+ ["terminal", "postscript enhanced"] ] )
64
+
65
+
66
+ assert( plot.to_gplot, \
67
+ "set output 'foo'\nset terminal postscript enhanced\n" )
68
+
69
+ end
70
+
71
+ def test_set
72
+ plot = Gnuplot::Plot.new do |p|
73
+ p.set "title", "foo"
74
+ end
75
+ assert "'foo'", plot["title"]
76
+
77
+ plot.set "title", "'foo'"
78
+ assert "'foo'", plot["title"]
79
+ end
80
+
81
+ end
82
+
83
+
84
+ require 'rbconfig'
85
+ CONFIG = Config::MAKEFILE_CONFIG
86
+
87
+ # This attempts to test the functions that comprise the gnuplot package. Most
88
+ # of the bug reports that I get for this package have to do with finding the
89
+ # gnuplot executable under different environments so that makes it difficult
90
+ # to test on a single environment. To try to get around this I'm using the
91
+ # rbconfig library and its path to the sh environment variable.
92
+
93
+ class GnuplotModuleTest
94
+
95
+ def test_which
96
+ # Put the spaces around the command to make sure that it gets stripped
97
+ # properly.
98
+ assert( CONFIG["SHELL"], Gnuplot::which(" sh " ) )
99
+ assert( CONFIG["SHELL"], Gnuplot::which( CONFIG["SHELL"] ) )
100
+ end
101
+
102
+
103
+ def test_gnuplot
104
+ cmd = Gnuplot.gnuplot
105
+ assert( Gnuplot::which("gnuplot") + " -persist", cmd )
106
+
107
+ cmd = Gnuplot.gnuplot(false)
108
+ assert( Gnuplot::which("gnuplot"), cmd )
109
+
110
+ # If I set the name of the gnuplot environment variable to a different
111
+ # name (one that is in the path) then I should get the shell name as the
112
+ # result of the gnuplot call.
113
+
114
+ ENV["RB_GNUPLOT"] = "sh"
115
+ assert( CONFIG["SHELL"], Gnuplot.gnuplot(false) )
116
+ end
117
+
118
+ end
119
+
120
+
metadata CHANGED
@@ -5,16 +5,16 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 2
7
7
  - 3
8
- - 3
9
- version: 2.3.3
8
+ - 4
9
+ version: 2.3.4
10
10
  platform: ruby
11
- authors:
12
- - see AUTHORS.txt
11
+ authors: []
12
+
13
13
  autorequire: gnuplot.rb
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-07-30 00:00:00 -06:00
17
+ date: 2010-08-02 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -24,17 +24,29 @@ executables: []
24
24
 
25
25
  extensions: []
26
26
 
27
- extra_rdoc_files: []
28
-
27
+ extra_rdoc_files:
28
+ - ChangeLog
29
+ - LICENSE.txt
30
+ - README.textile
29
31
  files:
32
+ - AUTHORS.txt
33
+ - ChangeLog
34
+ - LICENSE.txt
35
+ - README.textile
36
+ - Rakefile
30
37
  - lib/gnuplot.rb
38
+ - test/arrtest.rb
39
+ - test/histtest.rb
40
+ - test/multtest.rb
41
+ - test/sinwave.rb
42
+ - test/test_gnuplot.rb
31
43
  has_rdoc: true
32
44
  homepage: http://github.com/rdp/ruby_gnuplot/tree/master
33
45
  licenses: []
34
46
 
35
47
  post_install_message:
36
- rdoc_options: []
37
-
48
+ rdoc_options:
49
+ - --charset=UTF-8
38
50
  require_paths:
39
51
  - lib
40
52
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -60,5 +72,9 @@ rubygems_version: 1.3.7
60
72
  signing_key:
61
73
  specification_version: 3
62
74
  summary: Utility library to aid in interacting with gnuplot
63
- test_files: []
64
-
75
+ test_files:
76
+ - test/arrtest.rb
77
+ - test/histtest.rb
78
+ - test/multtest.rb
79
+ - test/sinwave.rb
80
+ - test/test_gnuplot.rb