2313
|
1 ## Copyright (C) 1996 John W. Eaton |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
933
|
19 |
2303
|
20 ## Originally written by Rick Niles <niles@axp745.gsfc.nasa.gov>. |
933
|
21 |
2311
|
22 ## usage: fmt = plot_opt (caller, opt) |
|
23 ## |
|
24 ## Decode plot option strings. |
|
25 ## |
|
26 ## If OPT is a valid option string, return a string of the form "w l 2" |
|
27 ## ("with lines 2"). Uses abbreviations for the options to avoid |
|
28 ## overrunning gnuplot's command line buffer unnecessarily. |
|
29 ## |
|
30 ## OPT can currently be some combination of the following: |
|
31 ## |
|
32 ## "-" for lines plot style (default). |
|
33 ## "." for dots plot style. |
|
34 ## "@" for points plot style. |
|
35 ## "-@" for linespoints plot style. |
|
36 ## "^" for impulses plot style. |
|
37 ## "L" for steps plot style. |
|
38 ## "#" for boxes plot style. |
|
39 ## "~" for errorbars plot style. |
|
40 ## "#~" for boxerrorbars plot style. |
|
41 ## "n" with n in 1-6 (wraps at 8), plot color |
|
42 ## "nm" with m in 1-6 (wraps at 6), point style (only valid with "@" or "-@") |
|
43 ## "c" where c is one of ["r", "g", "b", "m", "c", "w"] colors. |
|
44 ## |
|
45 ## Special points formats: |
|
46 ## |
|
47 ## "+", "*", "o", "x" will display points in that style. |
|
48 ## |
|
49 ## The legend may be fixed to include the name of the variable |
|
50 ## plotted in some future version of Octave. |
|
51 ## |
|
52 ## The color line styles have the following meanings on terminals |
|
53 ## that support color. |
|
54 ## |
|
55 ## Number Gnuplot colors (lines)points style |
|
56 ## 1 red "*" |
|
57 ## 2 green "+" |
|
58 ## 3 blue "o" |
|
59 ## 4 magenta "x" |
|
60 ## 5 cyan house |
|
61 ## 6 brown there exists |
933
|
62 |
2314
|
63 ## Author: jwe |
|
64 |
2311
|
65 function fmt = plot_opt (caller, opt) |
933
|
66 |
|
67 set_color = 0; |
|
68 set_symbol = 0; |
|
69 set_lines = 0; |
|
70 set_dots = 0; |
|
71 set_points = 0; |
|
72 set_impulses = 0; |
|
73 set_steps = 0; |
|
74 set_boxes = 0; |
|
75 set_errbars = 0; |
1479
|
76 more_opts = 1; |
933
|
77 |
|
78 WITH = "w"; |
|
79 LINES = "l"; |
|
80 LINESPOINTS = "linesp"; |
|
81 BOXERRORBARS = "boxer"; |
|
82 BOXES = "boxes"; |
|
83 POINTS = "p"; |
|
84 DOTS = "d"; |
|
85 IMPULSES = "i"; |
|
86 STEPS = "s"; |
|
87 ERRORBARS = "e"; |
|
88 |
|
89 if (nargin != 2) |
|
90 usage ("plot_opt (opt)"); |
|
91 endif |
|
92 |
|
93 if (! isstr (opt)) |
|
94 error ("plot_opt: argument must be a string"); |
|
95 endif |
|
96 |
1479
|
97 while (more_opts) |
933
|
98 |
2303
|
99 ## First get next char. |
933
|
100 |
|
101 if (max (size (opt)) > 1) |
2214
|
102 [char, opt] = sscanf (opt, "%c %s", "C"); |
933
|
103 else |
|
104 char = opt; |
1479
|
105 more_opts = 0; |
933
|
106 endif |
|
107 |
2303
|
108 ## Now set flags based on char. |
933
|
109 |
|
110 if (strcmp (char, "-")) |
|
111 set_lines = 1; |
|
112 elseif (strcmp (char, ".")) |
|
113 set_dots = 1; |
|
114 elseif (strcmp (char, "@")) |
|
115 set_points = 1; |
|
116 elseif (strcmp (char, "^")) |
|
117 set_impulses = 1; |
|
118 elseif (strcmp (char, "L")) |
|
119 set_steps = 1; |
|
120 elseif (strcmp (char, "~")) |
|
121 set_errbars = 1; |
|
122 elseif (strcmp (char, "#")) |
|
123 set_boxes = 1; |
|
124 elseif (strcmp (char, "0") || strcmp (char, "1") ... |
|
125 || strcmp (char, "2") || strcmp (char, "3") ... |
|
126 || strcmp (char, "4") || strcmp (char, "5") ... |
|
127 || strcmp (char, "6") || strcmp (char, "7") ... |
|
128 || strcmp (char, "8") || strcmp (char, "9")) |
|
129 if (set_color) |
|
130 set_points = 1; |
|
131 symbol = char; |
|
132 set_symbol = 1; |
|
133 else |
|
134 color = char; |
|
135 set_color = 1; |
|
136 endif |
|
137 elseif (strcmp (char, "r")) |
|
138 set_color = 1; |
|
139 color = "1"; |
|
140 elseif (strcmp (char, "g")) |
|
141 set_color = 1; |
|
142 color = "2"; |
|
143 elseif (strcmp (char, "b")) |
|
144 set_color = 1; |
|
145 color = "3"; |
|
146 elseif (strcmp (char, "m")) |
|
147 set_color = 1; |
|
148 color = "4"; |
|
149 elseif (strcmp (char, "c")) |
|
150 set_color = 1; |
|
151 color = "5"; |
|
152 elseif (strcmp (char, "w")) |
|
153 set_color = 1; |
|
154 color = "6"; |
|
155 elseif (strcmp (char, "*")) |
|
156 set_points = 1; |
|
157 set_symbol = 1; |
|
158 symbol = "1"; |
|
159 elseif (strcmp (char, "+")) |
|
160 set_points = 1; |
|
161 set_symbol = 1; |
|
162 symbol = "2"; |
|
163 elseif (strcmp (char, "o")) |
|
164 set_points = 1; |
|
165 set_symbol = 1; |
|
166 symbol = "3"; |
|
167 elseif (strcmp (char, "x")) |
|
168 set_points = 1; |
|
169 set_symbol = 1; |
|
170 symbol = "4"; |
|
171 else |
|
172 error (sprintf ("%s: unrecognized format character %s", caller, char)); |
|
173 endif |
|
174 endwhile |
|
175 |
2303
|
176 ## Now create format string. |
933
|
177 |
|
178 fmt = WITH; |
|
179 |
|
180 if (set_lines) |
|
181 if (set_points) |
|
182 fmt = strcat (fmt, " ", LINESPOINTS); |
|
183 else |
|
184 fmt = strcat (fmt, " ", LINES); |
|
185 endif |
|
186 elseif (set_boxes) |
|
187 if (set_errbars) |
|
188 fmt = strcat (fmt, " ", BOXERRORBARS); |
|
189 else |
|
190 fmt = strcat (fmt, " ", BOXES); |
|
191 endif |
|
192 elseif (set_points) |
|
193 fmt = strcat (fmt, " ", POINTS); |
|
194 elseif (set_dots) |
|
195 fmt = strcat (fmt, " ", DOTS); |
|
196 elseif (set_impulses) |
|
197 fmt = strcat (fmt, " ", IMPULSES); |
|
198 elseif (set_steps) |
|
199 fmt = strcat (fmt, " ", STEPS); |
|
200 elseif (set_errbars) |
|
201 fmt = strcat (fmt, " ", ERRORBARS); |
|
202 endif |
|
203 |
|
204 if (strcmp (fmt, WITH)) |
|
205 fmt = strcat (fmt, " ", LINES); |
|
206 endif |
|
207 |
|
208 if (set_color) |
|
209 fmt = strcat (fmt, " ", color); |
|
210 if (set_symbol) |
|
211 fmt = strcat (fmt, " ", symbol); |
|
212 endif |
|
213 elseif (set_symbol) |
|
214 fmt = strcat (fmt, " 1 ", symbol); |
|
215 endif |
|
216 |
|
217 endfunction |