bplot 0.0.1 → 0.0.2b
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +54 -0
- data/LICENSE +53 -53
- data/README +53 -52
- data/Roadmap +38 -0
- data/Tutorial +312 -0
- data/lib/bplot.rb +204 -181
- metadata +16 -25
data/ChangeLog
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
=== Version 0.0.2
|
2
|
+
|
3
|
+
* New plot API: The new API is incompatible with the old one, but it is
|
4
|
+
a major improvement. Now there are two ways to define plot styles:
|
5
|
+
|
6
|
+
* The syntax string method is more compact than the previous API.
|
7
|
+
|
8
|
+
* The named parameters are less compact but have an easier learning
|
9
|
+
curve than the previous API.
|
10
|
+
|
11
|
+
|
12
|
+
* Moved documentation to rdoc.
|
13
|
+
|
14
|
+
* Replaced the examples in the README with a full fleged Tutorial.
|
15
|
+
|
16
|
+
* Started a ChangeLog and a Roadmap file.
|
17
|
+
|
18
|
+
* Bugfix: Parse "with" command more reliably.
|
19
|
+
|
20
|
+
* Replaced the "replot" command with "refresh" which is more appropiate
|
21
|
+
for plotting data streams like BPLot does.
|
22
|
+
|
23
|
+
* New command: show
|
24
|
+
|
25
|
+
=== Version 0.0.1
|
26
|
+
|
27
|
+
* Initial release of BPlot using Gnuplot as a backend plotting engine.
|
28
|
+
|
29
|
+
[plot] Basic support for 2D plots. Includes setting the title and line
|
30
|
+
and point styles with Gnuplot and Matlab-like syntax:
|
31
|
+
|
32
|
+
b = BPlot.new
|
33
|
+
b.plot( [1,2,3,4,5], [2,4,8,16,32], 'ps 2 lw 2', 'rh--', 'Exponential')
|
34
|
+
|
35
|
+
b.plot(x, y, :title => 'Density', :gnuplot => 'lc 3 ps 1.5 lt 4 pt 5 w lp')
|
36
|
+
b.plot(x, y, :title => 'Density', :gnuplot => 'ps 1.5', :matlab => 'rh-')
|
37
|
+
b.plot(x, y, :t => 'Mass', :g => 'ps 2.5', :m => 'bh--')
|
38
|
+
|
39
|
+
b.plot(x, y, 'ps 2', 'rh-', x, z, 'ps 1.5', 'bs--')
|
40
|
+
b.plot(x, y, 'ps 2', 'rh-', 'Quadratic', x, z, 'ps 1.5', 'bs--', 'Linear')
|
41
|
+
|
42
|
+
|
43
|
+
[set] Support for plot settings via the Gnuplot 'set' command:
|
44
|
+
|
45
|
+
b.set('xrange [0:6]')
|
46
|
+
b.set('yrange [0:50]')
|
47
|
+
|
48
|
+
[replot] Support for the Gnuplot 'replot' command:
|
49
|
+
|
50
|
+
b.replot
|
51
|
+
|
52
|
+
[cmd] Support for sending raw instructions to the Gnuplot backend:
|
53
|
+
|
54
|
+
b.cmd('plot sin(x) tit "A plot without Ruby"')
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (C) 2012
|
1
|
+
Copyright (C) 2012 Daniel Carrera <dcarrera@gmail.com>
|
2
2
|
|
3
3
|
BPlot is free software; you can redistribute it and/or modify it under
|
4
4
|
the terms of the Artistic License 2.0 (reproduced below) as published
|
@@ -7,15 +7,15 @@ by The Perl Foundation.
|
|
7
7
|
http://www.perlfoundation.org/attachment/legal/artistic-2_0.txt
|
8
8
|
|
9
9
|
|
10
|
-
|
10
|
+
= The Artistic License 2.0
|
11
11
|
|
12
|
-
|
12
|
+
Copyright (c) 2000-2006, The Perl Foundation.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
Preamble
|
14
|
+
Everyone is permitted to copy and distribute verbatim copies
|
15
|
+
of this license document, but changing it is not allowed.
|
18
16
|
|
17
|
+
== Preamble
|
18
|
+
|
19
19
|
This license establishes the terms under which a given free software
|
20
20
|
Package may be copied, modified, distributed, and/or redistributed.
|
21
21
|
The intent is that the Copyright Holder maintains some artistic
|
@@ -27,60 +27,60 @@ license directly with the Copyright Holder of a given Package. If the
|
|
27
27
|
terms of this license do not permit the full use that you propose to
|
28
28
|
make of the Package, you should contact the Copyright Holder and seek
|
29
29
|
a different licensing arrangement.
|
30
|
+
|
31
|
+
== Definitions
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
"Copyright Holder" means the individual(s) or organization(s)
|
33
|
+
* "Copyright Holder" means the individual(s) or organization(s)
|
34
34
|
named in the copyright notice for the entire Package.
|
35
35
|
|
36
|
-
|
36
|
+
* "Contributor" means any party that has contributed code or other
|
37
37
|
material to the Package, in accordance with the Copyright Holder's
|
38
38
|
procedures.
|
39
39
|
|
40
|
-
|
40
|
+
* "You" and "your" means any person who would like to copy,
|
41
41
|
distribute, or modify the Package.
|
42
42
|
|
43
|
-
|
43
|
+
* "Package" means the collection of files distributed by the
|
44
44
|
Copyright Holder, and derivatives of that collection and/or of
|
45
45
|
those files. A given Package may consist of either the Standard
|
46
46
|
Version, or a Modified Version.
|
47
47
|
|
48
|
-
|
48
|
+
* "Distribute" means providing a copy of the Package or making it
|
49
49
|
accessible to anyone else, or in the case of a company or
|
50
50
|
organization, to others outside of your company or organization.
|
51
51
|
|
52
|
-
|
52
|
+
* "Distributor Fee" means any fee that you charge for Distributing
|
53
53
|
this Package or providing support for this Package to another
|
54
54
|
party. It does not mean licensing fees.
|
55
55
|
|
56
|
-
|
56
|
+
* "Standard Version" refers to the Package if it has not been
|
57
57
|
modified, or has been modified only in ways explicitly requested
|
58
58
|
by the Copyright Holder.
|
59
59
|
|
60
|
-
|
60
|
+
* "Modified Version" means the Package, if it has been changed, and
|
61
61
|
such changes were not explicitly requested by the Copyright
|
62
62
|
Holder.
|
63
63
|
|
64
|
-
|
64
|
+
* "Original License" means this Artistic License as Distributed with
|
65
65
|
the Standard Version of the Package, in its current version or as
|
66
66
|
it may be modified by The Perl Foundation in the future.
|
67
67
|
|
68
|
-
|
68
|
+
* "Source" form means the source code, documentation source, and
|
69
69
|
configuration files for the Package.
|
70
70
|
|
71
|
-
|
71
|
+
* "Compiled" form means the compiled bytecode, object code, binary,
|
72
72
|
or any other form resulting from mechanical transformation or
|
73
73
|
translation of the Source form.
|
74
74
|
|
75
75
|
|
76
|
-
Permission for Use and Modification Without Distribution
|
76
|
+
== Permission for Use and Modification Without Distribution
|
77
77
|
|
78
78
|
(1) You are permitted to use the Standard Version and create and use
|
79
79
|
Modified Versions for any purpose without restriction, provided that
|
80
80
|
you do not Distribute the Modified Version.
|
81
81
|
|
82
82
|
|
83
|
-
Permissions for Redistribution of the Standard Version
|
83
|
+
== Permissions for Redistribution of the Standard Version
|
84
84
|
|
85
85
|
(2) You may Distribute verbatim copies of the Source form of the
|
86
86
|
Standard Version of this Package in any medium without restriction,
|
@@ -95,7 +95,7 @@ Package will still be considered the Standard Version, and as such
|
|
95
95
|
will be subject to the Original License.
|
96
96
|
|
97
97
|
|
98
|
-
Distribution of Modified Versions of the Package as Source
|
98
|
+
== Distribution of Modified Versions of the Package as Source
|
99
99
|
|
100
100
|
(4) You may Distribute your Modified Version as Source (either gratis
|
101
101
|
or for a Distributor Fee, and with or without a Compiled form of the
|
@@ -104,33 +104,32 @@ from the Standard Version, including, but not limited to, documenting
|
|
104
104
|
any non-standard features, executables, or modules, and provided that
|
105
105
|
you do at least ONE of the following:
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
Distribution of Compiled Forms of the Standard Version
|
133
|
-
or Modified Versions without the Source
|
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 or Modified Versions without the Source
|
134
133
|
|
135
134
|
(5) You may Distribute Compiled forms of the Standard Version without
|
136
135
|
the Source, provided that you include complete instructions on how to
|
@@ -147,7 +146,7 @@ the Source, provided that you comply with Section 4 with respect to
|
|
147
146
|
the Source of the Modified Version.
|
148
147
|
|
149
148
|
|
150
|
-
Aggregating or Linking the Package
|
149
|
+
== Aggregating or Linking the Package
|
151
150
|
|
152
151
|
(7) You may aggregate the Package (either the Standard Version or
|
153
152
|
Modified Version) with other packages and Distribute the resulting
|
@@ -164,7 +163,7 @@ include the Package, and Distribute the result without restriction,
|
|
164
163
|
provided the result does not expose a direct interface to the Package.
|
165
164
|
|
166
165
|
|
167
|
-
Items That are Not Considered Part of a Modified Version
|
166
|
+
== Items That are Not Considered Part of a Modified Version
|
168
167
|
|
169
168
|
(9) Works (including, but not limited to, modules and scripts) that
|
170
169
|
merely extend or make use of the Package, do not, by themselves, cause
|
@@ -173,7 +172,7 @@ considered parts of the Package itself, and are not subject to the
|
|
173
172
|
terms of this license.
|
174
173
|
|
175
174
|
|
176
|
-
General Provisions
|
175
|
+
== General Provisions
|
177
176
|
|
178
177
|
(10) Any use, modification, and distribution of the Standard or
|
179
178
|
Modified Versions is governed by this Artistic License. By using,
|
@@ -200,6 +199,7 @@ infringement, then this Artistic License to you shall terminate on the
|
|
200
199
|
date that such litigation is filed.
|
201
200
|
|
202
201
|
(14) Disclaimer of Warranty:
|
202
|
+
|
203
203
|
THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS
|
204
204
|
IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
|
205
205
|
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
|
data/README
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
BPlot
|
2
|
-
|
3
|
-
|
1
|
+
= BPlot
|
2
|
+
|
3
|
+
BPlot is a 2D and 3D plotting module for SciRuby. It
|
4
|
+
provides an API familiar to Gnuplot users and to a lesser
|
5
|
+
extent Matlab users.
|
6
|
+
|
4
7
|
|
5
8
|
\ /
|
6
9
|
\ o ^ o /
|
@@ -15,8 +18,8 @@ BPlot -- A ploting module for SciRuby. It provides an API
|
|
15
18
|
(%%%)
|
16
19
|
!
|
17
20
|
|
18
|
-
SUMMARY / STATUS
|
19
|
-
|
21
|
+
== SUMMARY / STATUS
|
22
|
+
|
20
23
|
BPlot is in ALPHA status. Two dimmensional plots seem to work
|
21
24
|
well but they really need more testing. Surface plots and some
|
22
25
|
other features are not implemented yet.
|
@@ -31,72 +34,70 @@ no pre-requisites, as BPLot can work with either NMatrix objects
|
|
31
34
|
or with plain ruby arrays. That said, plotting is much easier
|
32
35
|
with NMatrix objects.
|
33
36
|
|
34
|
-
Try some of the commands below to get a feel of how it works.
|
35
37
|
|
38
|
+
== 2D PLOTS
|
39
|
+
|
40
|
+
The examples below illustrate how 2D plots work and what features
|
41
|
+
they have. Try out the examples to get a feel for BPlot.
|
42
|
+
|
43
|
+
require 'bplot'
|
44
|
+
|
45
|
+
x = [1,2,3,4,5]
|
46
|
+
y = [1,4,9,16,25]
|
47
|
+
z = [25,20,15,10,5]
|
48
|
+
|
49
|
+
b = BPlot.new
|
50
|
+
|
51
|
+
|
52
|
+
Send a raw command into Gnuplot.
|
53
|
+
|
54
|
+
b.cmd('plot sin(x) title "Plot without Ruby."')
|
55
|
+
|
56
|
+
|
57
|
+
Global settings.
|
58
|
+
|
59
|
+
b.set('xrange [0:6]')
|
60
|
+
b.set('yrange [0:30]')
|
61
|
+
b.set('title "Heading for the entire plot"')
|
62
|
+
|
63
|
+
|
64
|
+
Replot the most recent plot.
|
36
65
|
|
37
|
-
|
38
|
-
-------------------
|
66
|
+
b.replot
|
39
67
|
|
40
|
-
require 'bplot'
|
41
68
|
|
42
|
-
x = [1,2,3,4,5]
|
43
|
-
y = [1,4,9,16,25]
|
44
|
-
z = [25,20,15,10,5]
|
45
69
|
|
46
|
-
|
70
|
+
Basic plots.
|
47
71
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
b.cmd('plot sin(x) title "Plot without Ruby."')
|
72
|
+
b.plot(x, y)
|
73
|
+
b.plot(x, y, 'ps 2', 'rh')
|
74
|
+
b.plot(x, y, 'ps 2', 'rh..-', 'y = x^2')
|
52
75
|
|
53
76
|
|
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"')
|
77
|
+
The 'with' command on the gnuplot string takes precedence.
|
60
78
|
|
79
|
+
b.plot(x, y, 'ps 2 w lp', 'rh')
|
80
|
+
b.plot(x, y, 'ps 2 with steps', 'rh')
|
61
81
|
|
62
|
-
#
|
63
|
-
# Gnuplot 'replot' command.
|
64
|
-
#
|
65
|
-
b.replot
|
66
82
|
|
67
83
|
|
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')
|
84
|
+
Named parameters.
|
74
85
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
b.plot(x, y, 'ps 2 w lp', 'rh')
|
79
|
-
b.plot(x, y, 'ps 2 with steps', 'rh')
|
86
|
+
b.plot(x, y, :title => 'Density', :gnuplot => 'lc 3 ps 1.5 lt 4 pt 5 w lp')
|
87
|
+
b.plot(x, y, :title => 'Density', :gnuplot => 'ps 1.5', :matlab => 'rh-')
|
88
|
+
b.plot(x, y, :t => 'Mass', :g => 'ps 2.5', :m => 'bh--')
|
80
89
|
|
81
90
|
|
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
91
|
|
92
|
+
Multiple data sets (need not be the same length).
|
89
93
|
|
90
|
-
|
91
|
-
|
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')
|
94
|
+
b.plot(x, y, 'ps 2', 'rh-', x, z, 'ps 1.5', 'bs--')
|
95
|
+
b.plot(x, y, 'ps 2', 'rh-', 'Quadratic', x, z, 'ps 1.5', 'bs--', 'Linear')
|
95
96
|
|
96
97
|
|
97
|
-
|
98
|
+
Observe that named parameters must be at the end. Hence, they only apply to the last plot.
|
98
99
|
|
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.
|
100
|
+
b.plot(x, y, 'ps 2', 'rh-', 'Quadratic', x, z, 'ps 1.5', 'bs--', :t => 'Linear') # OK.
|
101
|
+
b.plot(x, y, 'ps 2', 'rh-', :t => 'Quadratic', x, z, 'ps 1.5', 'bs--', 'Linear') # ERROR.
|
101
102
|
|
102
103
|
|
data/Roadmap
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
= Roadmap
|
2
|
+
|
3
|
+
== Version 0.0.3
|
4
|
+
|
5
|
+
* X and Y error bars.
|
6
|
+
|
7
|
+
* Variable, data-dependent point size.
|
8
|
+
|
9
|
+
* Pie charts.
|
10
|
+
|
11
|
+
* Get NVector working.
|
12
|
+
|
13
|
+
* Movies with ffmpeg or avconv (or maybe also mencoder).
|
14
|
+
|
15
|
+
== Version 0.0.4
|
16
|
+
|
17
|
+
* Surface plots.
|
18
|
+
|
19
|
+
* New methods: meshgrid(), splot(), surf(), mesh()
|
20
|
+
|
21
|
+
== Version 0.0.5
|
22
|
+
|
23
|
+
* Complete coverage of top level Gnuplot functions.
|
24
|
+
|
25
|
+
* Proper testing on Windows and Mac.
|
26
|
+
|
27
|
+
== Version 0.1.0 (milestone)
|
28
|
+
|
29
|
+
* First release that is basically feature complete. It will
|
30
|
+
certainly need bugfixes and additions, but at this point
|
31
|
+
it should be be at least moderately stable.
|
32
|
+
|
33
|
+
* From this point on, the API should be stable.
|
34
|
+
|
35
|
+
* First beta release.
|
36
|
+
|
37
|
+
|
38
|
+
|
data/Tutorial
ADDED
@@ -0,0 +1,312 @@
|
|
1
|
+
= BPlot Tutorial (version 0.0.2)
|
2
|
+
|
3
|
+
BPlot is a powerful scientific plotting module for SciRuby. It can produce
|
4
|
+
high quality 2D (and soon 3D) plots thanks to its Gnuplot backend. Gnuplot
|
5
|
+
is a mature free software tool for scientific plotting. BPlot presents a
|
6
|
+
convenient API to SciRuby users and converts all instructions into Gnuplot
|
7
|
+
commands.
|
8
|
+
|
9
|
+
The BPlot API contains a mixture of Matlab features and Gnuplot features.
|
10
|
+
The API provides a soft transition for users familiar with either one of
|
11
|
+
these plotting tools. Over time, Matlab users are likelky to pick up some
|
12
|
+
Gnuplot and Gnuplot users are likely to pick up some Matlab.
|
13
|
+
|
14
|
+
|
15
|
+
== Status
|
16
|
+
|
17
|
+
BPlot is in ALPHA status. Two dimensional plots seem to work well but they
|
18
|
+
really need more testing. Surface plots and some other features are not
|
19
|
+
implemented yet. Use at your own risk.
|
20
|
+
|
21
|
+
|
22
|
+
== Installation
|
23
|
+
|
24
|
+
BPlot is provided as a Ruby gem. Installation should be as easy as:
|
25
|
+
|
26
|
+
gem install bplot
|
27
|
+
|
28
|
+
It is recommended that you install and use NMatrix, but BPlot is designed
|
29
|
+
to also work with regular Ruby arrains. Therefore, NMatrix is not actually
|
30
|
+
a dependency. That said, plotting is likely to be easier with NMatrix.
|
31
|
+
|
32
|
+
|
33
|
+
== Getting Started
|
34
|
+
|
35
|
+
After installation, start the Ruby shell with the command "irb" (if you have
|
36
|
+
Ruby version 1.8, type "irb -rubygems"). Then type the following:
|
37
|
+
|
38
|
+
require 'bplot'
|
39
|
+
|
40
|
+
b = BPlot.new
|
41
|
+
|
42
|
+
|
43
|
+
This code loads the BPlot module and creates an instance of BPLot. Every
|
44
|
+
instance of BPlot has its own dedicated Gnuplot process. In this way, BPlot
|
45
|
+
lets you control multiple Gnuplot processes from a single script.
|
46
|
+
|
47
|
+
|
48
|
+
=== Raw commands
|
49
|
+
|
50
|
+
Though not done often, BPlot lets you send raw commands into the Gnuplot
|
51
|
+
backend. The *cmd* method allows you to bypass BPlot, so you can use any
|
52
|
+
Gnuplot feature that is not implemented in BPlot.
|
53
|
+
|
54
|
+
b.cmd('plot sin(x) title "Plot without Ruby."')
|
55
|
+
|
56
|
+
|
57
|
+
=== Settings
|
58
|
+
|
59
|
+
The *set* and *unset* methods are thin wrappers around the Gnuplot commands
|
60
|
+
of the same names. These methods can be used to set *A LOT* of options.
|
61
|
+
However, nothing is drawn until the user issues a plotting command. You can
|
62
|
+
use "set" to create any number of output files (postscript, png, svg, EPS
|
63
|
+
with LaTeX, etc.).
|
64
|
+
|
65
|
+
|
66
|
+
b.set('terminal postscript enhanced color')
|
67
|
+
b.set('output "myplot.ps"')
|
68
|
+
|
69
|
+
b.cmd('plot sin(x) title "Plot without Ruby."')
|
70
|
+
|
71
|
+
b.set('terminal wxt')
|
72
|
+
|
73
|
+
|
74
|
+
You can use "set" to set many global options. For example:
|
75
|
+
|
76
|
+
b.set('xrange [0:6]')
|
77
|
+
b.set('yrange [0:30]')
|
78
|
+
b.set('xlabel "This is the X Axis"')
|
79
|
+
b.set('ylabel "This is the Y Axis"')
|
80
|
+
b.set('title "A title for the whole plot"')
|
81
|
+
|
82
|
+
As mentioned earlier, these settings will not be visible until you issue
|
83
|
+
another plotting command. However, you can find out their values using
|
84
|
+
the *show* command:
|
85
|
+
|
86
|
+
b.show('terminal')
|
87
|
+
b.show('xrange')
|
88
|
+
b.show('title')
|
89
|
+
|
90
|
+
|
91
|
+
=== Refresh
|
92
|
+
|
93
|
+
This command reformats and redraws the current plot with the latest
|
94
|
+
settings. This is useful for viewing a plot with different "set"
|
95
|
+
options, or for generating the same plot for several output formats.
|
96
|
+
|
97
|
+
b.refresh
|
98
|
+
|
99
|
+
|
100
|
+
=== 2D Plots
|
101
|
+
|
102
|
+
By far the most important method is *plot*. This is the command that
|
103
|
+
draws 2D plots using NMatrix objectts or Ruby arrays. This method has
|
104
|
+
several optional parameters mostly related to the look of individual
|
105
|
+
data sets (e.g. colour, line thickness, point style, etc.).
|
106
|
+
|
107
|
+
==== Named parameters
|
108
|
+
|
109
|
+
The most intuitive way to configure the *plot* command is with named
|
110
|
+
parameter. The following example illustrates the +:title+ and +:color+
|
111
|
+
options:
|
112
|
+
|
113
|
+
x = [1,2,3,4,5]
|
114
|
+
y = [1,4,9,16,25]
|
115
|
+
|
116
|
+
b.plot(x, y)
|
117
|
+
b.plot(x, y, :title => "My Data", :color => "blue")
|
118
|
+
b.plot(x, y, :title => "My Data", :color => "#33aa55")
|
119
|
+
|
120
|
+
The colour can be specified as an RGB hex string ("#33aa55") or any colour
|
121
|
+
name that Gnuplot recognizes. To see a full list type *b.show('colornames')*,
|
122
|
+
but some examples include:
|
123
|
+
|
124
|
+
red dark-red light-red black white
|
125
|
+
green dark-green light-green grey0 gray0
|
126
|
+
blue dark-blue light-blue grey10 gray10
|
127
|
+
cyan dark-cyan light-cyan grey20 gray20
|
128
|
+
magenta dark-magenta light-magenta grey30 gray30
|
129
|
+
grey dark-grey light-grey grey40 gray40
|
130
|
+
gray dark-gray light-gray grey50 gray50
|
131
|
+
pink dark-pink light-pink grey60 gray60
|
132
|
+
orange dark-orange light-orange grey70 gray70
|
133
|
+
yellow dark-yellow grey80 gray80
|
134
|
+
violet dark-violet grey90 gray90
|
135
|
+
coral light-coral grey100 gray100
|
136
|
+
|
137
|
+
You can instruct BPlot to connect points with lines using the +:lines+
|
138
|
+
option, and you can configure the point style with the +:points+ option.
|
139
|
+
Both parameters take a style string that specifies the line-width/point-size
|
140
|
+
and the line-type/point-type separated by a semicolon:
|
141
|
+
|
142
|
+
b.plot(x, y, :lines => "2;dashed", :points => "2;open-circle")
|
143
|
+
b.plot(x, y, :lines => "1;dots", :points => "1.5;filled-square")
|
144
|
+
|
145
|
+
You can leave either option blank. For example, `:lines => ";dashed"` defines
|
146
|
+
a dashed line of the default thickness ("1"), while `:lines => "2;"` defines
|
147
|
+
a line of width "2" of the default line type ("solid"). As shown in the example,
|
148
|
+
sizes can be decimal. The valid line and point types are listed below in full:
|
149
|
+
|
150
|
+
Line Types Point Types
|
151
|
+
---------- -----------
|
152
|
+
solid + plus
|
153
|
+
dashed x cross
|
154
|
+
dots * star
|
155
|
+
dot-dashed open-square solid-square
|
156
|
+
dot-dot-dashed open-circle solid-circle
|
157
|
+
open-diamond solid-diamond
|
158
|
+
open-up-triangle solid-up-triangle
|
159
|
+
open-down-triangle solid-down-triangle
|
160
|
+
|
161
|
+
==== Style strings
|
162
|
+
|
163
|
+
As you write more plots, named parameters quickly become cumbersome. BPlot
|
164
|
+
supports a powerful and compact style string that is derived from Matlab
|
165
|
+
and Gnuplot. You can insert a single string with the syntax:
|
166
|
+
|
167
|
+
<-MATLAB-STRING-> ; <-DATA-TITLE-> ; <-GNUPLOT-STRING->
|
168
|
+
|
169
|
+
The best way to learn this is to see it in action. The Matlab string can
|
170
|
+
be used to set the colour, line style and point styles:
|
171
|
+
|
172
|
+
b.plot(x, y, 'r')
|
173
|
+
b.plot(x, y, 'g')
|
174
|
+
b.plot(x, y, 'm')
|
175
|
+
|
176
|
+
b.plot(x, y, 'go')
|
177
|
+
b.plot(x, y, 'bs')
|
178
|
+
b.plot(x, y, 'm^')
|
179
|
+
|
180
|
+
b.plot(x, y, 'r-')
|
181
|
+
b.plot(x, y, 'm--')
|
182
|
+
b.plot(x, y, 'k.-')
|
183
|
+
|
184
|
+
b.plot(x, y, 'rd-')
|
185
|
+
b.plot(x, y, 'rv:')
|
186
|
+
b.plot(x, y, 'rh..-')
|
187
|
+
|
188
|
+
|
189
|
+
The meaning of all the symbols available is described below:
|
190
|
+
|
191
|
+
Colours Line Styles
|
192
|
+
------- -----------
|
193
|
+
r == red - == solid
|
194
|
+
g == green : == dots
|
195
|
+
b == blue -- == dashed
|
196
|
+
m == magenta .- == dot dashed
|
197
|
+
c == cyan ..- == dot dot dashed
|
198
|
+
y == yellow
|
199
|
+
k == black
|
200
|
+
|
201
|
+
|
202
|
+
Point Styles
|
203
|
+
------------
|
204
|
+
+ == plus \
|
205
|
+
x == cross \
|
206
|
+
* == star \
|
207
|
+
o == open circle \ ___ Matlab styles with direct
|
208
|
+
s == solid square / Gnuplot equivalents.
|
209
|
+
^ == solid up triangle /
|
210
|
+
v == solid down triangle /
|
211
|
+
d == solid diamond /
|
212
|
+
|
213
|
+
< == open up triangle \
|
214
|
+
> == open down triangle \ ____ Matlab styles that were mapped
|
215
|
+
p == open diamond / to a different Gnuplot style.
|
216
|
+
h == solid circle /
|
217
|
+
|
218
|
+
q == open square \ _____ Non-Matlab style, inserted to add
|
219
|
+
/ full coverage of Gnuplot styles.
|
220
|
+
|
221
|
+
|
222
|
+
As in Matlab, you can add a title after a semicolon (e.g. "rh;My Plot;").
|
223
|
+
You can also add a Gnuplot style string after the second semicolon. The
|
224
|
+
Gnuplot string gives you access to the full power of Gnuplot. Try the
|
225
|
+
examples below:
|
226
|
+
|
227
|
+
b.plot(x, y, 'rh;Quadratic')
|
228
|
+
b.plot(x, y, 'rh;Quadratic;ps 2')
|
229
|
+
|
230
|
+
b.plot(x, y, 'ro--;y = x^2;ps 2 lw 2')
|
231
|
+
b.plot(x, y, 'rs.-;y = x^2;ps 1.5 lw 1')
|
232
|
+
|
233
|
+
b.plot(x, y, 'r--;;smooth cspline')
|
234
|
+
b.plot(x, y, 'r--;;with steps')
|
235
|
+
b.plot(x, y, 'r- ;;with impulses')
|
236
|
+
|
237
|
+
|
238
|
+
The Matlab portion of the string may some times disagree with the Gnuplot portion.
|
239
|
+
For example 'rs--' implies that the plot should display both data points (drawn as
|
240
|
+
squares) and lines (drawn as dashed lines). But what if the Gnuplot string specifies
|
241
|
+
"with lines" (as opposed to "with linespoints")? If there is a disagreement, the
|
242
|
+
Gnuplot instrucion takes presedence. For example:
|
243
|
+
|
244
|
+
b.plot(x, y, 'rs;;with linespoints')
|
245
|
+
b.plot(x, y, 'rs;;with steps')
|
246
|
+
|
247
|
+
|
248
|
+
[Warning:] Do not enter a title in the Gnuplot style string. Doing so is not supported
|
249
|
+
and will fail when you least expect it. Use the method provided instead.
|
250
|
+
|
251
|
+
==== Multiple plots
|
252
|
+
|
253
|
+
You can have any number of data sets plotted in the same window, using the same
|
254
|
+
"plot" command. To do this, simply include all the data sets separated by style
|
255
|
+
strings (the style strings can be blank).
|
256
|
+
|
257
|
+
|
258
|
+
x = [1,2,3,4,5]
|
259
|
+
y1 = [1,4,9,16,25]
|
260
|
+
y2 = [25,20,15,10,5]
|
261
|
+
y3 = [20,10,20,10,5]
|
262
|
+
|
263
|
+
b.plot(x, y1, "", x, y2)
|
264
|
+
b.plot(x, y1, "", x, y2, "", x, y3)
|
265
|
+
b.plot(x, y1, 's;;ps 1', x, y2, 'h;;ps 2', x, y3, 'o;;ps 3 lw 1.5')
|
266
|
+
b.plot(x, y1, 's-;;ps 1', x, y2, 'h--;;ps 2', x, y3, 'o:;;ps 3 lw 1.5')
|
267
|
+
b.plot(x, y1, 'ro--;Quadratic', x, y2, 'b^:;Linear')
|
268
|
+
|
269
|
+
[Warning:] Resist the temptation of skipping the blank style strings. Doing so will
|
270
|
+
work for now, but will likely stop working soon, when I add support for
|
271
|
+
plotting error bars.
|
272
|
+
|
273
|
+
|
274
|
+
Learning the compact style syntax is especially important for multiple plots because
|
275
|
+
they named parameters like :title can only be included once in a plot command, and
|
276
|
+
they always apply to the last data set only.
|
277
|
+
|
278
|
+
There is also a *multiplot* method which can be "abused" to plot several differnet
|
279
|
+
data sets in the same plot, using several different plot commands.
|
280
|
+
|
281
|
+
b.multiplot do
|
282
|
+
b.set('yrange [0:30]')
|
283
|
+
b.plot(x, y1, :color => 'red', :lines => '1;dashed')
|
284
|
+
b.plot(x, y2, :color => 'blue', :lines => '1;dots')
|
285
|
+
b.plot(x, y3, :color => 'black',:points=> '3;open-circles')
|
286
|
+
end
|
287
|
+
|
288
|
+
But the real power of *multiplot* is the ability to place several entirely separate
|
289
|
+
plots on the same page, using any layout that you wish. To see an exaple of how this
|
290
|
+
works, try the following examples:
|
291
|
+
|
292
|
+
b.multiplot('layout 1,3 title "Multiplot layout 1x3" ') do
|
293
|
+
b.set('title "Quadratic"')
|
294
|
+
b.plot(x, y1, :color => 'red', :lines => '1;dashed')
|
295
|
+
b.set('title "Linear"')
|
296
|
+
b.plot(x, y2, :color => 'blue', :lines => '1;dots')
|
297
|
+
b.set('title "Zig Zag"')
|
298
|
+
b.plot(x, y3, 'ko--')
|
299
|
+
end
|
300
|
+
|
301
|
+
== How to explore more: Gnuplot demos
|
302
|
+
|
303
|
+
An excellent way to explore what you can do with BPlot is to go through the Gnuplot
|
304
|
+
demos page:
|
305
|
+
|
306
|
+
http://gnuplot.sourceforge.net/demo/
|
307
|
+
|
308
|
+
Not everything in this page is implemented in BPlot, but this page is a great way
|
309
|
+
to explore what's possible with Gnuplot, and Gnuplot ultimately determines what is
|
310
|
+
possible with BPlot.
|
311
|
+
|
312
|
+
|
data/lib/bplot.rb
CHANGED
@@ -1,89 +1,4 @@
|
|
1
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
2
|
TODO: SURFACE PLOTS
|
88
3
|
-------------------
|
89
4
|
|
@@ -101,6 +16,7 @@ b.splot(x,y,z)
|
|
101
16
|
#
|
102
17
|
# I'll document this function when I implement surface plots.
|
103
18
|
#
|
19
|
+
=begin
|
104
20
|
def meshgrid(x,y)
|
105
21
|
warn "Input to meshgrid() must be 1 dimensional" if x.dim > 1
|
106
22
|
warn "Input to meshgrid() must be 1 dimensional" if y.dim > 1
|
@@ -113,8 +29,26 @@ def meshgrid(x,y)
|
|
113
29
|
|
114
30
|
return xx, yy.transpose
|
115
31
|
end
|
32
|
+
=end
|
33
|
+
|
116
34
|
|
35
|
+
# BPlot is a 2D and 3D plotting module for SciRuby. It provides a
|
36
|
+
# simple API that will be familiar to Gnuplot users and to a lesser
|
37
|
+
# extent Matlab users. BPlot is in ALPHA status. Two dimmensional
|
38
|
+
# plots seem to work well but they really need more testing. Also,
|
39
|
+
# the API is not yet settled and may change without warning. Many
|
40
|
+
# features are not yet implemented, including surface plots.
|
117
41
|
class BPlot
|
42
|
+
# === Create new engine
|
43
|
+
#
|
44
|
+
# Every call to BPlot#new creates a new instance of Gnuplot. You can
|
45
|
+
# have multiple instances of Gnuplot in the same Ruby script.
|
46
|
+
#
|
47
|
+
# === Example
|
48
|
+
#
|
49
|
+
# b.BPlot.new
|
50
|
+
# b.cmd('plot sin(x)')
|
51
|
+
#
|
118
52
|
def initialize()
|
119
53
|
#
|
120
54
|
# Every instance of BPlot has its own gnuplot process.
|
@@ -130,30 +64,112 @@ class BPlot
|
|
130
64
|
end
|
131
65
|
|
132
66
|
#
|
133
|
-
#
|
134
|
-
#
|
67
|
+
# === Issue raw command
|
68
|
+
#
|
69
|
+
# Send a raw command to the Gnuplot backend.
|
70
|
+
# This gives the user more control over plotting engine.
|
71
|
+
#
|
72
|
+
# === Example
|
73
|
+
#
|
74
|
+
# b.BPlot.new
|
75
|
+
# b.cmd('plot sin(x)')
|
135
76
|
#
|
136
77
|
def cmd(str)
|
137
78
|
@pipe.puts str
|
138
79
|
end
|
139
80
|
|
140
81
|
#
|
141
|
-
# Settings
|
82
|
+
# === Settings
|
83
|
+
#
|
84
|
+
# This method is a thin wrapper around the Gnuplot "set" command.
|
85
|
+
# It can be used to set *a lot* of options. However, nothing is
|
86
|
+
# drawn until the user issues a plotting command. See the examples
|
87
|
+
# below for a quick overview. See the Gnuplot documentation for
|
88
|
+
# more details.
|
89
|
+
#
|
90
|
+
# === Examples
|
91
|
+
#
|
92
|
+
# b.set('terminal enhanced postscript color')
|
93
|
+
# b.set('output "myplot.ps"')
|
94
|
+
# b.set('xrange [0:10]')
|
95
|
+
# b.set('yrange [0:50]')
|
96
|
+
# b.set('xlabel "This is the X Axis"')
|
97
|
+
# b.set('ylabel "This is the Y Axis"')
|
98
|
+
# b.set('title "A title for the whole plot"')
|
142
99
|
#
|
143
100
|
def set(str)
|
144
101
|
@pipe.puts "set #{str}"
|
145
102
|
end
|
146
103
|
|
104
|
+
# === Settings
|
105
|
+
#
|
106
|
+
# This method is a thin wrapper around the Gnuplot "unset" command.
|
107
|
+
# It is used to reset settings back to their default values. See
|
108
|
+
# the documentation on "set" for more information. See also the
|
109
|
+
# Gnuplot documentaion for "set" and "unset".
|
110
|
+
def unset(str)
|
111
|
+
@pipe.puts "unset #{str}"
|
112
|
+
end
|
113
|
+
|
114
|
+
# === Show
|
147
115
|
#
|
148
|
-
#
|
116
|
+
# The `set` command can be used to set *lots* of options. No screen is
|
117
|
+
# drawn, however, until a plotting command is given. The *show* command
|
118
|
+
# shows their settings; show('all') shows all the settings.
|
149
119
|
#
|
150
|
-
def
|
151
|
-
@pipe.puts "
|
120
|
+
def show(str)
|
121
|
+
@pipe.puts "show #{str}"
|
152
122
|
end
|
153
123
|
|
154
124
|
#
|
155
|
-
#
|
125
|
+
# === Refresh
|
126
|
+
#
|
127
|
+
# This command reformats and redraws the current plot with the latest
|
128
|
+
# settings. This is useful for viewing a plot with different "set"
|
129
|
+
# options, or for generating the same plot for several output formats.
|
130
|
+
#
|
131
|
+
# === Example
|
156
132
|
#
|
133
|
+
# b.set('terminal postscript')
|
134
|
+
# b.set('output "myplot.ps"')
|
135
|
+
# b.refresh
|
136
|
+
#
|
137
|
+
# b.set('terminal png')
|
138
|
+
# b.set('output "myplot.png"')
|
139
|
+
# b.refresh
|
140
|
+
#
|
141
|
+
def refresh()
|
142
|
+
@pipe.puts "refresh"
|
143
|
+
end
|
144
|
+
|
145
|
+
# == Multiplot
|
146
|
+
#
|
147
|
+
# In multiplot mode, multiple plot commands are placed togeher in the
|
148
|
+
# same window. This can be a convenient alternative to having a very
|
149
|
+
# long multiple-line plot command. It allso allows you to add plots
|
150
|
+
# using loops and other constructions.
|
151
|
+
#
|
152
|
+
# == Examples
|
153
|
+
#
|
154
|
+
# b.multiplot do
|
155
|
+
# plot(x, y1)
|
156
|
+
# plot(x, y2)
|
157
|
+
# plot(x, y3)
|
158
|
+
# end
|
159
|
+
#
|
160
|
+
# b.multiplot do
|
161
|
+
# (0..10).each { |t| plot( x, sin(x + v*t) ) }
|
162
|
+
# end
|
163
|
+
def multiplot(opts='')
|
164
|
+
@pipe.puts "set multiplot #{opts}"
|
165
|
+
yield if block_given?
|
166
|
+
@pipe.puts "unset multiplot"
|
167
|
+
end
|
168
|
+
|
169
|
+
# == 2D Plotting
|
170
|
+
#
|
171
|
+
# This is the key method in BPlot, as it is responsible for all 2D plots. This
|
172
|
+
# method is currently in a state of flux and is for the moment undocumented.
|
157
173
|
def plot(*args)
|
158
174
|
|
159
175
|
data = []
|
@@ -202,107 +218,116 @@ class BPlot
|
|
202
218
|
|
203
219
|
private
|
204
220
|
|
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
221
|
#
|
215
222
|
# - Get all the stye information for the next plot from 'args'.
|
216
223
|
# - Return the styles as a string, and the remainder of 'args'.
|
217
224
|
#
|
218
225
|
def styles(args)
|
219
226
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
227
|
+
with = ''
|
228
|
+
title = ''
|
229
|
+
color = ''
|
230
|
+
style = " '-' "
|
231
|
+
|
232
|
+
if args[0].is_a?(String)
|
233
|
+
|
234
|
+
opts = args.shift
|
235
|
+
opts = opts.split(/;/)
|
236
|
+
|
237
|
+
#
|
238
|
+
# Gnuplot 'with' beats Matlab's.
|
239
|
+
#
|
240
|
+
with = gnu_with(opts[2]) if opts[2]
|
241
|
+
with = mat_with(opts[0]) if with == ''
|
242
|
+
|
243
|
+
style << mat_style(opts[0])
|
244
|
+
style << gnu_style(opts[2]) if opts[2]
|
245
|
+
|
246
|
+
title = opts[1] if opts.length >= 1
|
247
|
+
end
|
248
|
+
|
249
|
+
if args[0].is_a?(Hash)
|
250
|
+
#
|
251
|
+
# Incidentally, if we are here, this is the end of the plot command.
|
252
|
+
#
|
253
|
+
opts = args.shift
|
254
|
+
|
255
|
+
title = opts[:title] if opts[:title]
|
256
|
+
color = opts[:color] if opts[:color]
|
257
|
+
|
258
|
+
#
|
259
|
+
# Infer the 'with' command for :lines and :points.
|
260
|
+
#
|
261
|
+
if opts[:lines]
|
262
|
+
lw, lt = opts[:lines].split(/;/)
|
255
263
|
|
264
|
+
lw = 1 if lw == ''
|
265
|
+
lt = 1 if lt == '' or lt == nil
|
266
|
+
lt = 1 if lt.to_s =~ /solid/i
|
267
|
+
lt = 2 if lt.to_s =~ /dashed/i
|
268
|
+
lt = 3 if lt.to_s =~ /dots/i
|
269
|
+
lt = 4 if lt.to_s =~ /dot-dashed/i
|
270
|
+
lt = 5 if lt.to_s =~ /dot-dot-dashed/i
|
256
271
|
|
257
|
-
#
|
258
|
-
|
259
|
-
|
260
|
-
|
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]
|
272
|
+
style << " lw #{lw} lt #{lt} "
|
273
|
+
end
|
274
|
+
if opts[:points]
|
275
|
+
ps, pt = opts[:points].split(/;/)
|
264
276
|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
277
|
+
ps = 1 if ps == ''
|
278
|
+
pt = 1 if pt == ''
|
279
|
+
pt = 1 if pt == '+'
|
280
|
+
pt = 2 if pt == 'x' or pt == 'X'
|
281
|
+
pt = 3 if pt == '*'
|
282
|
+
pt = 1 if pt.to_s =~ /plus/i
|
283
|
+
pt = 2 if pt.to_s =~ /cross/i
|
284
|
+
pt = 3 if pt.to_s =~ /star/i
|
285
|
+
pt = 4 if pt.to_s =~ /open-square/i
|
286
|
+
pt = 5 if pt.to_s =~ /solid-square/i
|
287
|
+
pt = 6 if pt.to_s =~ /open-circle/i
|
288
|
+
pt = 7 if pt.to_s =~ /solid-circle/i
|
289
|
+
pt = 8 if pt.to_s =~ /open-up-triangle/i
|
290
|
+
pt = 9 if pt.to_s =~ /solid-up-triangle/i
|
291
|
+
pt = 10 if pt.to_s =~ /open-down-triangle/i
|
292
|
+
pt = 11 if pt.to_s =~ /solid-down-triangle/i
|
293
|
+
pt = 12 if pt.to_s =~ /open-diamond/i
|
294
|
+
pt = 13 if pt.to_s =~ /solid-diamond/i
|
271
295
|
|
272
|
-
#
|
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]
|
296
|
+
style << " ps #{ps} pt #{pt} "
|
278
297
|
end
|
279
298
|
|
299
|
+
#
|
300
|
+
# "with" strings from both Matlab and Gnuplot take precedence.
|
301
|
+
#
|
302
|
+
# In other words: Gnuplot > Matlab > Named parameters.
|
303
|
+
#
|
304
|
+
if with == ''
|
305
|
+
with = 'with lines' if opts[:lines]
|
306
|
+
with = 'with points' if opts[:points]
|
307
|
+
with = 'with linespoints' if opts[:lines] and opts[:points]
|
308
|
+
end
|
280
309
|
end
|
281
310
|
|
282
311
|
|
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
312
|
#
|
292
|
-
#
|
313
|
+
# Finish up the command (title, colour, 'with', etc).
|
293
314
|
#
|
294
|
-
|
315
|
+
style << " lc rgb \"#{color}\" " if color != ''
|
316
|
+
style << " title \"#{title}\" "
|
317
|
+
style << with if with
|
295
318
|
|
296
|
-
|
297
|
-
# Return 'this_plot' and what is left of 'args'.
|
298
|
-
#
|
299
|
-
return this_plot, args
|
319
|
+
return style, args
|
300
320
|
end
|
301
321
|
|
302
322
|
|
303
323
|
def gnu_with(s)
|
304
|
-
|
324
|
+
regex = /\b([wW][iI]?[tT]?[hH]? +\w+)/
|
325
|
+
s =~ regex ? s.scan(regex).last.first : ''
|
326
|
+
end
|
327
|
+
def gnu_style(str)
|
328
|
+
str.gsub(/\b([wW][iI]?[tT]?[hH]? +\w+)/, '')
|
305
329
|
end
|
330
|
+
|
306
331
|
def mat_with(s)
|
307
332
|
wp = s =~ /[xsovdph<>+*^]/ ? true : false
|
308
333
|
wl = s =~ /[-:.]/ ? true : false
|
@@ -311,13 +336,6 @@ class BPlot
|
|
311
336
|
return " with points " if wp
|
312
337
|
return " with lines " if wl
|
313
338
|
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
339
|
def mat_style(mat)
|
322
340
|
style = '';
|
323
341
|
|
@@ -341,10 +359,15 @@ class BPlot
|
|
341
359
|
style << " pt 13 " if mat =~ /d/
|
342
360
|
|
343
361
|
# Styles I cannot duplicate properly:
|
344
|
-
style << " pt 8 " if mat =~ /</
|
345
|
-
style << " pt 10 " if mat =~ />/
|
346
|
-
style << " pt
|
347
|
-
style << " pt 7 " if mat =~ /h/
|
362
|
+
style << " pt 8 " if mat =~ /</ # open up triangle.
|
363
|
+
style << " pt 10 " if mat =~ />/ # open down triangle.
|
364
|
+
style << " pt 12 " if mat =~ /p/ # open diamond
|
365
|
+
style << " pt 7 " if mat =~ /h/ # solid circle
|
366
|
+
|
367
|
+
#
|
368
|
+
# Extra remaining style (non-Matlab).
|
369
|
+
#
|
370
|
+
style << " pt 4 " if mat =~ /q/ # open square
|
348
371
|
|
349
372
|
# Line styles
|
350
373
|
style << " lt 1 " if mat =~ /-/ and mat !~ /--/ and mat !~ /\.-/ and mat !~ /\.\.-/
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bplot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2b
|
5
|
+
prerelease: 5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Daniel Carrera
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: A 2D and 3D plotting module for SciRuby that uses syntax from Gnuplot
|
15
15
|
and to a lesser degree Matlab.
|
@@ -20,6 +20,9 @@ extra_rdoc_files: []
|
|
20
20
|
files:
|
21
21
|
- README
|
22
22
|
- LICENSE
|
23
|
+
- Tutorial
|
24
|
+
- ChangeLog
|
25
|
+
- Roadmap
|
23
26
|
- lib/bplot.rb
|
24
27
|
homepage: http://rubygems.org/gems/bplot
|
25
28
|
licenses: []
|
@@ -31,26 +34,14 @@ post_install_message: ! "*******************************************************
|
|
31
34
|
is a bee.\n /( )\\ I like bees.\n /
|
32
35
|
\ (%%%%%) \\\n (%%%)\n !\n\n ***
|
33
36
|
WARNING ***\n\nBPlot is in ALPHA status. Two dimmensional plots seem to work\nwell
|
34
|
-
but they really need more testing.
|
35
|
-
implemented yet
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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"
|
37
|
+
but they really need more testing. Many features such as\nsurface plots have not
|
38
|
+
been implemented yet. The backend uses\nGnuplot, so you must have Gnuplot installed
|
39
|
+
and in your PATH.\n\nThe plotting command mixes Matlab and Gnuplot syntax. The addition\nof
|
40
|
+
Matlab syntax to Gnuplot makes plotting immensely easier while\nstill retaining
|
41
|
+
the power of Gnuplot. BPlot provides a comfortable\nenvironment for Matlab and Gnuplot
|
42
|
+
users. Matlab users will learn\nsome Gnuplot and Gnuplot users will leran some Matlab.\n\nDon't
|
43
|
+
forget to read the tutorial!\n\nBPlot comes with a nice tutorial that documents
|
44
|
+
every feature.\nIf you don't have a copy of the tutorial, you can get one here:\n\nhttps://github.com/dcarrera/bplot/blob/master/Tutorial\n\n\n***********************************************************\n"
|
54
45
|
rdoc_options: []
|
55
46
|
require_paths:
|
56
47
|
- lib
|
@@ -63,9 +54,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
55
|
none: false
|
65
56
|
requirements:
|
66
|
-
- - ! '
|
57
|
+
- - ! '>'
|
67
58
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
59
|
+
version: 1.3.1
|
69
60
|
requirements: []
|
70
61
|
rubyforge_project:
|
71
62
|
rubygems_version: 1.8.11
|