bplot 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/LICENSE +210 -0
  2. data/README +102 -0
  3. data/lib/bplot.rb +360 -0
  4. metadata +75 -0
data/LICENSE ADDED
@@ -0,0 +1,210 @@
1
+ Copyright (C) 2012, Daniel Carrera <dcarrera@gmail.com>
2
+
3
+ BPlot is free software; you can redistribute it and/or modify it under
4
+ the terms of the Artistic License 2.0 (reproduced below) as published
5
+ by The Perl Foundation.
6
+
7
+ http://www.perlfoundation.org/attachment/legal/artistic-2_0.txt
8
+
9
+
10
+ The Artistic License 2.0
11
+
12
+ Copyright (c) 2000-2006, The Perl Foundation.
13
+
14
+ Everyone is permitted to copy and distribute verbatim copies
15
+ of this license document, but changing it is not allowed.
16
+
17
+ Preamble
18
+
19
+ This license establishes the terms under which a given free software
20
+ Package may be copied, modified, distributed, and/or redistributed.
21
+ The intent is that the Copyright Holder maintains some artistic
22
+ control over the development of that Package while still keeping the
23
+ Package available as open source and free software.
24
+
25
+ You are always permitted to make arrangements wholly outside of this
26
+ license directly with the Copyright Holder of a given Package. If the
27
+ terms of this license do not permit the full use that you propose to
28
+ make of the Package, you should contact the Copyright Holder and seek
29
+ a different licensing arrangement.
30
+
31
+ Definitions
32
+
33
+ "Copyright Holder" means the individual(s) or organization(s)
34
+ named in the copyright notice for the entire Package.
35
+
36
+ "Contributor" means any party that has contributed code or other
37
+ material to the Package, in accordance with the Copyright Holder's
38
+ procedures.
39
+
40
+ "You" and "your" means any person who would like to copy,
41
+ distribute, or modify the Package.
42
+
43
+ "Package" means the collection of files distributed by the
44
+ Copyright Holder, and derivatives of that collection and/or of
45
+ those files. A given Package may consist of either the Standard
46
+ Version, or a Modified Version.
47
+
48
+ "Distribute" means providing a copy of the Package or making it
49
+ accessible to anyone else, or in the case of a company or
50
+ organization, to others outside of your company or organization.
51
+
52
+ "Distributor Fee" means any fee that you charge for Distributing
53
+ this Package or providing support for this Package to another
54
+ party. It does not mean licensing fees.
55
+
56
+ "Standard Version" refers to the Package if it has not been
57
+ modified, or has been modified only in ways explicitly requested
58
+ by the Copyright Holder.
59
+
60
+ "Modified Version" means the Package, if it has been changed, and
61
+ such changes were not explicitly requested by the Copyright
62
+ Holder.
63
+
64
+ "Original License" means this Artistic License as Distributed with
65
+ the Standard Version of the Package, in its current version or as
66
+ it may be modified by The Perl Foundation in the future.
67
+
68
+ "Source" form means the source code, documentation source, and
69
+ configuration files for the Package.
70
+
71
+ "Compiled" form means the compiled bytecode, object code, binary,
72
+ or any other form resulting from mechanical transformation or
73
+ translation of the Source form.
74
+
75
+
76
+ Permission for Use and Modification Without Distribution
77
+
78
+ (1) You are permitted to use the Standard Version and create and use
79
+ Modified Versions for any purpose without restriction, provided that
80
+ you do not Distribute the Modified Version.
81
+
82
+
83
+ Permissions for Redistribution of the Standard Version
84
+
85
+ (2) You may Distribute verbatim copies of the Source form of the
86
+ Standard Version of this Package in any medium without restriction,
87
+ either gratis or for a Distributor Fee, provided that you duplicate
88
+ all of the original copyright notices and associated disclaimers. At
89
+ your discretion, such verbatim copies may or may not include a
90
+ Compiled form of the Package.
91
+
92
+ (3) You may apply any bug fixes, portability changes, and other
93
+ modifications made available from the Copyright Holder. The resulting
94
+ Package will still be considered the Standard Version, and as such
95
+ will be subject to the Original License.
96
+
97
+
98
+ Distribution of Modified Versions of the Package as Source
99
+
100
+ (4) You may Distribute your Modified Version as Source (either gratis
101
+ or for a Distributor Fee, and with or without a Compiled form of the
102
+ Modified Version) provided that you clearly document how it differs
103
+ from the Standard Version, including, but not limited to, documenting
104
+ any non-standard features, executables, or modules, and provided that
105
+ you do at least ONE of the following:
106
+
107
+ (a) make the Modified Version available to the Copyright Holder
108
+ of the Standard Version, under the Original License, so that the
109
+ Copyright Holder may include your modifications in the Standard
110
+ Version.
111
+
112
+ (b) ensure that installation of your Modified Version does not
113
+ prevent the user installing or running the Standard Version. In
114
+ addition, the Modified Version must bear a name that is different
115
+ from the name of the Standard Version.
116
+
117
+ (c) allow anyone who receives a copy of the Modified Version to
118
+ make the Source form of the Modified Version available to others
119
+ under
120
+
121
+ (i) the Original License or
122
+
123
+ (ii) a license that permits the licensee to freely copy,
124
+ modify and redistribute the Modified Version using the same
125
+ licensing terms that apply to the copy that the licensee
126
+ received, and requires that the Source form of the Modified
127
+ Version, and of any works derived from it, be made freely
128
+ available in that license fees are prohibited but Distributor
129
+ Fees are allowed.
130
+
131
+
132
+ Distribution of Compiled Forms of the Standard Version
133
+ or Modified Versions without the Source
134
+
135
+ (5) You may Distribute Compiled forms of the Standard Version without
136
+ the Source, provided that you include complete instructions on how to
137
+ get the Source of the Standard Version. Such instructions must be
138
+ valid at the time of your distribution. If these instructions, at any
139
+ time while you are carrying out such distribution, become invalid, you
140
+ must provide new instructions on demand or cease further distribution.
141
+ If you provide valid instructions or cease distribution within thirty
142
+ days after you become aware that the instructions are invalid, then
143
+ you do not forfeit any of your rights under this license.
144
+
145
+ (6) You may Distribute a Modified Version in Compiled form without
146
+ the Source, provided that you comply with Section 4 with respect to
147
+ the Source of the Modified Version.
148
+
149
+
150
+ Aggregating or Linking the Package
151
+
152
+ (7) You may aggregate the Package (either the Standard Version or
153
+ Modified Version) with other packages and Distribute the resulting
154
+ aggregation provided that you do not charge a licensing fee for the
155
+ Package. Distributor Fees are permitted, and licensing fees for other
156
+ components in the aggregation are permitted. The terms of this license
157
+ apply to the use and Distribution of the Standard or Modified Versions
158
+ as included in the aggregation.
159
+
160
+ (8) You are permitted to link Modified and Standard Versions with
161
+ other works, to embed the Package in a larger work of your own, or to
162
+ build stand-alone binary or bytecode versions of applications that
163
+ include the Package, and Distribute the result without restriction,
164
+ provided the result does not expose a direct interface to the Package.
165
+
166
+
167
+ Items That are Not Considered Part of a Modified Version
168
+
169
+ (9) Works (including, but not limited to, modules and scripts) that
170
+ merely extend or make use of the Package, do not, by themselves, cause
171
+ the Package to be a Modified Version. In addition, such works are not
172
+ considered parts of the Package itself, and are not subject to the
173
+ terms of this license.
174
+
175
+
176
+ General Provisions
177
+
178
+ (10) Any use, modification, and distribution of the Standard or
179
+ Modified Versions is governed by this Artistic License. By using,
180
+ modifying or distributing the Package, you accept this license. Do not
181
+ use, modify, or distribute the Package, if you do not accept this
182
+ license.
183
+
184
+ (11) If your Modified Version has been derived from a Modified
185
+ Version made by someone other than you, you are nevertheless required
186
+ to ensure that your Modified Version complies with the requirements of
187
+ this license.
188
+
189
+ (12) This license does not grant you the right to use any trademark,
190
+ service mark, tradename, or logo of the Copyright Holder.
191
+
192
+ (13) This license includes the non-exclusive, worldwide,
193
+ free-of-charge patent license to make, have made, use, offer to sell,
194
+ sell, import and otherwise transfer the Package with respect to any
195
+ patent claims licensable by the Copyright Holder that are necessarily
196
+ infringed by the Package. If you institute patent litigation
197
+ (including a cross-claim or counterclaim) against any party alleging
198
+ that the Package constitutes direct or contributory patent
199
+ infringement, then this Artistic License to you shall terminate on the
200
+ date that such litigation is filed.
201
+
202
+ (14) Disclaimer of Warranty:
203
+ THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
204
+ IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
205
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
206
+ NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL
207
+ LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL
208
+ BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
209
+ DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF
210
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README ADDED
@@ -0,0 +1,102 @@
1
+ BPlot -- A ploting module for SciRuby. It provides an API
2
+ familiar to Gnuplot users and to a lesser extent
3
+ Matlab users.
4
+
5
+ \ /
6
+ \ o ^ o /
7
+ \ ( ) /
8
+ ____________(%%%%%%%)____________
9
+ ( / / )%%%%%%%( \ \ )
10
+ (___/___/__/ \__\___\___)
11
+ ( / /(%%%%%%%)\ \ )
12
+ (__/___/ (%%%%%%%) \___\__) A hard-working bee.
13
+ /( )\
14
+ / (%%%%%) \
15
+ (%%%)
16
+ !
17
+
18
+ SUMMARY / STATUS
19
+ ----------------
20
+ BPlot is in ALPHA status. Two dimmensional plots seem to work
21
+ well but they really need more testing. Surface plots and some
22
+ other features are not implemented yet.
23
+
24
+ BPlot uses Gnuplot as the plotting engine, so you need to have
25
+ Gnuplot installed and in your PATH. BPlot lets you use straight
26
+ Gnuplot commands, but it also borrows some useful style syntax
27
+ from Matlab to make plotting even better.
28
+
29
+ To install, I think 'gem install bplot' should do it. There are
30
+ no pre-requisites, as BPLot can work with either NMatrix objects
31
+ or with plain ruby arrays. That said, plotting is much easier
32
+ with NMatrix objects.
33
+
34
+ Try some of the commands below to get a feel of how it works.
35
+
36
+
37
+ EXAMPLES: 2D PLOTS
38
+ -------------------
39
+
40
+ require 'bplot'
41
+
42
+ x = [1,2,3,4,5]
43
+ y = [1,4,9,16,25]
44
+ z = [25,20,15,10,5]
45
+
46
+ b = BPlot.new
47
+
48
+ #
49
+ # Send a raw command into Gnuplot.
50
+ #
51
+ b.cmd('plot sin(x) title "Plot without Ruby."')
52
+
53
+
54
+ #
55
+ # Gnuplot 'set' command.
56
+ #
57
+ b.set('xrange [0:6]')
58
+ b.set('yrange [0:30]')
59
+ b.set('title "Heading for the entire plot"')
60
+
61
+
62
+ #
63
+ # Gnuplot 'replot' command.
64
+ #
65
+ b.replot
66
+
67
+
68
+ #
69
+ # Basic plots.
70
+ #
71
+ b.plot(x, y)
72
+ b.plot(x, y, 'ps 2', 'rh')
73
+ b.plot(x, y, 'ps 2', 'rh..-', 'y = x^2')
74
+
75
+ #
76
+ # The 'with' command on the gnuplot string takes precedence.
77
+ #
78
+ b.plot(x, y, 'ps 2 w lp', 'rh')
79
+ b.plot(x, y, 'ps 2 with steps', 'rh')
80
+
81
+
82
+ #
83
+ # Named parameters.
84
+ #
85
+ b.plot(x, y, :title => 'Density', :gnuplot => 'lc 3 ps 1.5 lt 4 pt 5 w lp')
86
+ b.plot(x, y, :title => 'Density', :gnuplot => 'ps 1.5', :matlab => 'rh-')
87
+ b.plot(x, y, :t => 'Mass', :g => 'ps 2.5', :m => 'bh--')
88
+
89
+
90
+ #
91
+ # Multiple data sets (need not be the same length).
92
+ #
93
+ b.plot(x, y, 'ps 2', 'rh-', x, z, 'ps 1.5', 'bs--')
94
+ b.plot(x, y, 'ps 2', 'rh-', 'Quadratic', x, z, 'ps 1.5', 'bs--', 'Linear')
95
+
96
+
97
+ # Observe that named parameters must be at the end. Hence, they only apply to the last plot.
98
+
99
+ b.plot(x, y, 'ps 2', 'rh-', 'Quadratic', x, z, 'ps 1.5', 'bs--', :t => 'Linear') # OK.
100
+ b.plot(x, y, 'ps 2', 'rh-', :t => 'Quadratic', x, z, 'ps 1.5', 'bs--', 'Linear') # ERROR.
101
+
102
+
data/lib/bplot.rb ADDED
@@ -0,0 +1,360 @@
1
+ =begin
2
+ BPlot -- A ploting module for SciRuby. It provides an API
3
+ familiar to Gnuplot users and to a lesser extent
4
+ Matlab users.
5
+
6
+ \ /
7
+ \ o ^ o /
8
+ \ ( ) /
9
+ ____________(%%%%%%%)____________
10
+ ( / / )%%%%%%%( \ \ )
11
+ (___/___/__/ \__\___\___)
12
+ ( / /(%%%%%%%)\ \ )
13
+ (__/___/ (%%%%%%%) \___\__) A hard-working bee.
14
+ /( )\
15
+ / (%%%%%) \
16
+ (%%%)
17
+ !
18
+
19
+ EXAMPLES: 2D PLOTS
20
+ -------------------
21
+
22
+ require 'bplot'
23
+
24
+ x = [1,2,3,4,5]
25
+ y = [1,4,9,16,25]
26
+ z = [25,20,15,10,5]
27
+
28
+ b = BPlot.new
29
+
30
+ #
31
+ # Send a raw command into Gnuplot.
32
+ #
33
+ b.cmd('plot sin(x) title "Plot without Ruby."')
34
+
35
+
36
+ #
37
+ # Gnuplot 'set' command.
38
+ #
39
+ b.set('xrange [0:6]')
40
+ b.set('yrange [0:30]')
41
+ b.set('title "Heading for the entire plot"')
42
+
43
+
44
+ #
45
+ # Gnuplot 'replot' command.
46
+ #
47
+ b.replot
48
+
49
+
50
+ #
51
+ # Basic plots.
52
+ #
53
+ b.plot(x, y)
54
+ b.plot(x, y, 'ps 2', 'rh')
55
+ b.plot(x, y, 'ps 2', 'rh--', 'y = x^2')
56
+
57
+ #
58
+ # The 'with' command on the gnuplot string takes precedence.
59
+ #
60
+ b.plot(x, y, 'ps 2 w lp', 'rh')
61
+ b.plot(x, y, 'ps 2 with steps', 'rh')
62
+
63
+
64
+ #
65
+ # Named parameters.
66
+ #
67
+ b.plot(x, y, :title => 'Density', :gnuplot => 'lc 3 ps 1.5 lt 4 pt 5 w lp')
68
+ b.plot(x, y, :title => 'Density', :gnuplot => 'ps 1.5', :matlab => 'rh-')
69
+ b.plot(x, y, :t => 'Mass', :g => 'ps 2.5', :m => 'bh--')
70
+
71
+
72
+ #
73
+ # Multiple data sets (need not be the same length).
74
+ #
75
+ b.plot(x, y, 'ps 2', 'rh-', x, z, 'ps 1.5', 'bs--')
76
+ b.plot(x, y, 'ps 2', 'rh-', 'Quadratic', x, z, 'ps 1.5', 'bs--', 'Linear')
77
+
78
+
79
+ # Observe that named parameters must be at the end. Hence, they only apply to the last plot.
80
+
81
+ b.plot(x, y, 'ps 2', 'rh-', 'Quadratic', x, z, 'ps 1.5', 'bs--', :t => 'Linear') # OK.
82
+ b.plot(x, y, 'ps 2', 'rh-', :t => 'Quadratic', x, z, 'ps 1.5', 'bs--', 'Linear') # ERROR.
83
+
84
+
85
+
86
+ ========================================
87
+ TODO: SURFACE PLOTS
88
+ -------------------
89
+
90
+ x = N[1,2,3,4,5]
91
+ y = x
92
+
93
+ x,y = meshgrid(x,y)
94
+
95
+ z = x*x + y*y
96
+
97
+ b.splot(x,y,z)
98
+
99
+ =end
100
+
101
+ #
102
+ # I'll document this function when I implement surface plots.
103
+ #
104
+ def meshgrid(x,y)
105
+ warn "Input to meshgrid() must be 1 dimensional" if x.dim > 1
106
+ warn "Input to meshgrid() must be 1 dimensional" if y.dim > 1
107
+
108
+ xn = x.shape[0]
109
+ yn = y.shape[0]
110
+
111
+ xx = NMatrix.new( [xn,xn], (0..xn-1).map { |i| x[i] } )
112
+ yy = NMatrix.new( [yn,yn], (0..yn-1).map { |i| y[i] } )
113
+
114
+ return xx, yy.transpose
115
+ end
116
+
117
+ class BPlot
118
+ def initialize()
119
+ #
120
+ # Every instance of BPlot has its own gnuplot process.
121
+ #
122
+ @pipe = IO.popen("gnuplot","w")
123
+
124
+ #
125
+ # Configure Gnuplot.
126
+ #
127
+ @pipe.puts "set terminal wxt" # Nice GUI for plots.
128
+ @pipe.puts "set termoption dashed" # Needed for 'r--', 'r.-', 'r:'
129
+ @pipe.puts "set termoption enhanced" # Support superscripts + subscripts.
130
+ end
131
+
132
+ #
133
+ # Command -- Send a raw command into Gnuplot.
134
+ # Gives the user more control over Gnuplot.
135
+ #
136
+ def cmd(str)
137
+ @pipe.puts str
138
+ end
139
+
140
+ #
141
+ # Settings -- Wrapper for 'set' command in Gnuplot.
142
+ #
143
+ def set(str)
144
+ @pipe.puts "set #{str}"
145
+ end
146
+
147
+ #
148
+ # Replot -- Wrapper for the 'replot' command in Gnuplot.
149
+ #
150
+ def replot
151
+ @pipe.puts "replot"
152
+ end
153
+
154
+ #
155
+ # 2D plotting -- Mostly like Gnuplot, but adding colours and line/point styles from Matlab.
156
+ #
157
+ def plot(*args)
158
+
159
+ data = []
160
+ all_plots = ''
161
+ while args.length > 0
162
+ #
163
+ # NEXT PLOT
164
+ #
165
+ # First two values are the (x,y) points.
166
+ data << args.shift
167
+ data << args.shift
168
+
169
+ # - Get the settings for this plot.
170
+ # - If 'args' is not empty, there is another plot.
171
+ this_plot, args = styles(args)
172
+ all_plots << this_plot
173
+ all_plots << ', ' if args.length > 0
174
+ end
175
+
176
+ # TODO:
177
+ # - Check for both Array and NMatrix.
178
+ # - But make sure the program works without NMatrix loaded.
179
+ #
180
+
181
+ #
182
+ # Each plot needs a separate stream of data separated by 'e' ("end").
183
+ #
184
+ nstreams = data.length / 2
185
+
186
+ stream = (1..nstreams).map { |s|
187
+ x = data.shift
188
+ y = data.shift
189
+ n = x.is_a?(Array) ? x.length - 1 : x.shape[0] - 1
190
+
191
+ (0..n).map { |i| "#{x[i]} #{y[i]}\n" }.join + "e\n"
192
+ }.join
193
+
194
+ @pipe.puts "plot #{all_plots} \n#{stream}"
195
+ end
196
+
197
+ ###############################
198
+ #
199
+ # PRIVATE METHODS
200
+ #
201
+ ###############################
202
+
203
+ private
204
+
205
+ #
206
+ # TODO: Can I avoid using strings here?
207
+ #
208
+ def finished(args)
209
+ args.length == 0 or
210
+ args[0].class.to_s == 'Array' or
211
+ args[0].class.to_s == 'NMatrix'
212
+ end
213
+
214
+ #
215
+ # - Get all the stye information for the next plot from 'args'.
216
+ # - Return the styles as a string, and the remainder of 'args'.
217
+ #
218
+ def styles(args)
219
+
220
+ g_with = ''
221
+ m_with = ''
222
+ str_index = 0
223
+ this_plot = " '-' "
224
+ while !finished(args)
225
+ if args[0].is_a?(String)
226
+
227
+ g_with << gnu_with(args[0]) if str_index == 0
228
+ m_with << mat_with(args[0]) if str_index == 1
229
+
230
+ this_plot << gnu_style(args.shift) if str_index == 0
231
+ this_plot << mat_style(args.shift) if str_index == 1
232
+ this_plot << tit_style(args.shift) if str_index == 2
233
+
234
+ str_index += 1
235
+
236
+ elsif args[0].is_a?(Hash)
237
+ opts = args.shift
238
+
239
+ # Gnuplot style.
240
+ g_with << gnu_with(opts[:g]) if opts[:g]
241
+ g_with << gnu_with(opts[:gn]) if opts[:gn]
242
+ g_with << gnu_with(opts[:gnu]) if opts[:gnu]
243
+ g_with << gnu_with(opts[:gnup]) if opts[:gnup]
244
+ g_with << gnu_with(opts[:gnupl]) if opts[:gnupl]
245
+ g_with << gnu_with(opts[:gnuplo]) if opts[:gnuplo]
246
+ g_with << gnu_with(opts[:gnuplot]) if opts[:gnuplot]
247
+
248
+ this_plot << gnu_style(opts[:g]) if opts[:g]
249
+ this_plot << gnu_style(opts[:gn]) if opts[:gn]
250
+ this_plot << gnu_style(opts[:gnu]) if opts[:gnu]
251
+ this_plot << gnu_style(opts[:gnup]) if opts[:gnup]
252
+ this_plot << gnu_style(opts[:gnupl]) if opts[:gnupl]
253
+ this_plot << gnu_style(opts[:gnuplo]) if opts[:gnuplo]
254
+ this_plot << gnu_style(opts[:gnuplot]) if opts[:gnuplot]
255
+
256
+
257
+ # Matlab style.
258
+ m_with << mat_with(opts[:m]) if opts[:m]
259
+ m_with << mat_with(opts[:ma]) if opts[:ma]
260
+ m_with << mat_with(opts[:mat]) if opts[:mat]
261
+ m_with << mat_with(opts[:matl]) if opts[:matl]
262
+ m_with << mat_with(opts[:matla]) if opts[:matla]
263
+ m_with << mat_with(opts[:matlab]) if opts[:matlab]
264
+
265
+ this_plot << mat_style(opts[:m]) if opts[:m]
266
+ this_plot << mat_style(opts[:ma]) if opts[:ma]
267
+ this_plot << mat_style(opts[:mat]) if opts[:mat]
268
+ this_plot << mat_style(opts[:matl]) if opts[:matl]
269
+ this_plot << mat_style(opts[:matla]) if opts[:matla]
270
+ this_plot << mat_style(opts[:matlab]) if opts[:matlab]
271
+
272
+ # Title.
273
+ this_plot << tit_style(opts[:t]) if opts[:t]
274
+ this_plot << tit_style(opts[:ti]) if opts[:ti]
275
+ this_plot << tit_style(opts[:tit]) if opts[:tit]
276
+ this_plot << tit_style(opts[:titl]) if opts[:titl]
277
+ this_plot << tit_style(opts[:title]) if opts[:title]
278
+ end
279
+
280
+ end
281
+
282
+
283
+ # - The user may insert a 'with' in the gnuplot string which conflicts with matlab.
284
+ # - In this case, the gnuplot string takes precdence.
285
+ # - If you insert the word "with" in a title inside the gnuplot string... it's your
286
+ # own fault. I told you to put the title in the :title parameter.
287
+
288
+ this_plot << g_with
289
+ this_plot << m_with if g_with == ''
290
+
291
+ #
292
+ # If there is no title, add a blank one.
293
+ #
294
+ this_plot << " title '' " if this_plot !~ /tit/
295
+
296
+ #
297
+ # Return 'this_plot' and what is left of 'args'.
298
+ #
299
+ return this_plot, args
300
+ end
301
+
302
+
303
+ def gnu_with(s)
304
+ s =~ /w/ ? s.scan(/([wW][iI]?[tT]?[hH]? +\w+)/).last.first : ''
305
+ end
306
+ def mat_with(s)
307
+ wp = s =~ /[xsovdph<>+*^]/ ? true : false
308
+ wl = s =~ /[-:.]/ ? true : false
309
+
310
+ return " with linespoints " if wp and wl
311
+ return " with points " if wp
312
+ return " with lines " if wl
313
+ end
314
+
315
+ def tit_style(str)
316
+ " title \"#{str}\" "
317
+ end
318
+ def gnu_style(str)
319
+ str.gsub(/([wW][iI]?[tT]?[hH]? +\w+)/, '')
320
+ end
321
+ def mat_style(mat)
322
+ style = '';
323
+
324
+ # Colour:
325
+ style << " lc 1 " if mat =~ /r/
326
+ style << " lc 2 " if mat =~ /g/
327
+ style << " lc 3 " if mat =~ /b/
328
+ style << " lc 4 " if mat =~ /m/
329
+ style << " lc 5 " if mat =~ /c/
330
+ style << " lc 6 " if mat =~ /y/
331
+ style << " lc 7 " if mat =~ /k/
332
+
333
+ # Line styles:
334
+ style << " pt 1 " if mat =~ /\+/
335
+ style << " pt 2 " if mat =~ /x/
336
+ style << " pt 3 " if mat =~ /\*/
337
+ style << " pt 5 " if mat =~ /s/
338
+ style << " pt 6 " if mat =~ /o/
339
+ style << " pt 9 " if mat =~ /\^/
340
+ style << " pt 11 " if mat =~ /v/
341
+ style << " pt 13 " if mat =~ /d/
342
+
343
+ # Styles I cannot duplicate properly:
344
+ style << " pt 8 " if mat =~ /</
345
+ style << " pt 10 " if mat =~ />/
346
+ style << " pt 4 " if mat =~ /p/
347
+ style << " pt 7 " if mat =~ /h/
348
+
349
+ # Line styles
350
+ style << " lt 1 " if mat =~ /-/ and mat !~ /--/ and mat !~ /\.-/ and mat !~ /\.\.-/
351
+ style << " lt 4 " if mat =~ /\.-/ and mat !~ /\.\.-/
352
+ style << " lt 5 " if mat =~ /\.\.-/
353
+ style << " lt 2 " if mat =~ /--/
354
+ style << " lt 3 " if mat =~ /:/
355
+
356
+ return style
357
+ end
358
+ end
359
+
360
+
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bplot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Carrera
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A 2D and 3D plotting module for SciRuby that uses syntax from Gnuplot
15
+ and to a lesser degree Matlab.
16
+ email: dcarrera@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README
22
+ - LICENSE
23
+ - lib/bplot.rb
24
+ homepage: http://rubygems.org/gems/bplot
25
+ licenses: []
26
+ post_install_message: ! "***********************************************************\nWelcome
27
+ to BPlot: A plotting module for SciRuby!\n\n \\ /\n \\
28
+ \ o ^ o /\n \\ ( ) /\n ____________(%%%%%%%)____________\n
29
+ \ ( / / )%%%%%%%( \\ \\ )\n (___/___/__/ \\__\\___\\___)\n
30
+ \ ( / /(%%%%%%%)\\ \\ )\n (__/___/ (%%%%%%%) \\___\\__) This
31
+ is a bee.\n /( )\\ I like bees.\n /
32
+ \ (%%%%%) \\\n (%%%)\n !\n\n ***
33
+ WARNING ***\n\nBPlot is in ALPHA status. Two dimmensional plots seem to work\nwell
34
+ but they really need more testing. Surface plots and some\nother features are not
35
+ implemented yet.\n\nBPlot uses Gnuplot as the plotting engine, so you need to have\nGnuplot
36
+ installed and in your PATH. BPlot lets you use straight\nGnuplot commands, but it
37
+ also borrows some useful style syntax\nfrom Matlab to make plotting even better.\n\nBPlot
38
+ can work with either NMatrix objects or with plain Ruby\narrays. Try some of the
39
+ commands below to get a feel of how\nit works:\n\nrequire 'bplot'\n\nx = [1,2,3,4,5]\ny
40
+ = [1,4,9,16,25]\nz = [25,20,15,10,5]\n\nb = BPlot.new\n\n# Send a raw command into
41
+ Gnuplot.\nb.cmd('plot sin(x) title \"Plot without Ruby.\"')\n\n# Gnuplot 'set' command.\nb.set('xrange
42
+ [0:6]')\nb.set('yrange [0:30]')\nb.set('title \"Heading for the entire plot\"')\n\n#
43
+ Gnuplot 'replot' command.\nb.replot\n\n# Basic plots.\nb.plot(x, y)\nb.plot(x, y,
44
+ 'ps 2', 'rh')\nb.plot(x, y, 'ps 2', 'rh--', 'y = x^2')\n\n# The 'with' command on
45
+ the gnuplot string takes precedence.\nb.plot(x, y, 'ps 2 w lp', 'rh')\nb.plot(x,
46
+ y, 'ps 2 with steps', 'rh')\n\n# Named parameters.\nb.plot(x, y, :title => 'Mass',
47
+ :gnuplot => 'ps 1.5', :matlab => 'rh-')\nb.plot(x, y, :t => 'Mass', :g => 'ps 2.5',
48
+ :m => 'rh-')\n\n# Multiple data sets (need not be the same length).\nb.plot(x, y,
49
+ 'ps 2', 'rh-', x, z, 'ps 1.5', 'bs--')\nb.plot(x, y, 'ps 2', 'rh-', 'Quadratic',
50
+ x, z, 'ps 1.5', 'bs--', 'Linear')\n\n# Named parameters only allowed for the last
51
+ data set.\nb.plot(x, y, 'ps 2', 'rh-', 'Quadratic', x, z, 'ps 1.5', 'bs--',
52
+ :t => 'Linear') # OK.\nb.plot(x, y, 'ps 2', 'rh-', :t => 'Quadratic', x, z, 'ps
53
+ 1.5', 'bs--', 'Linear') # ERROR.\n\n***********************************************************\n"
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 1.8.11
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: A ploting module for SciRuby with a Gnuplot backend.
75
+ test_files: []