Mercurial > hg > octave-lyh
comparison scripts/plot/axis.m @ 3667:f7f94396dd81
[project @ 2000-05-13 06:31:28 by jwe]
author | jwe |
---|---|
date | Sat, 13 May 2000 06:31:29 +0000 |
parents | f8dde1807dee |
children | b0a68efa1295 |
comparison
equal
deleted
inserted
replaced
3666:301e0da5b455 | 3667:f7f94396dd81 |
---|---|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA | 17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
18 ## 02111-1307, USA. | 18 ## 02111-1307, USA. |
19 | 19 |
20 ## -*- texinfo -*- | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} axis (@var{limits}) | 21 ## @deftypefn {Function File} {} axis (@var{limits}) |
22 ## Sets the axis limits for plots. | 22 ## Set axis limits for plots. |
23 ## | 23 ## |
24 ## The argument @var{limits} should be a 2, 4, or 6 element vector. The | 24 ## The argument @var{limits} should be a 2, 4, or 6 element vector. The |
25 ## first and second elements specify the lower and upper limits for the x | 25 ## first and second elements specify the lower and upper limits for the x |
26 ## axis. The third and fourth specify the limits for the y axis, and the | 26 ## axis. The third and fourth specify the limits for the y axis, and the |
27 ## fifth and sixth specify the limits for the z axis. | 27 ## fifth and sixth specify the limits for the z axis. |
28 ## | 28 ## |
29 ## With no arguments, @code{axis} turns autoscaling on. | |
30 ## | |
31 ## If your plot is already drawn, then you need to use @code{replot} before | 29 ## If your plot is already drawn, then you need to use @code{replot} before |
32 ## the new axis limits will take effect. You can get this to happen | 30 ## the new axis limits will take effect. You can get this to happen |
33 ## automatically by setting the built-in variable @code{automatic_replot} | 31 ## automatically by setting the built-in variable @code{automatic_replot} |
34 ## to a nonzero value. | 32 ## to a nonzero value. |
33 ## | |
34 ## Without any arguments, @code{axis} turns autoscaling on. | |
35 ## | |
36 ## A second argument may be used to specify various formats. For | |
37 ## example, | |
38 ## | |
39 ## @example | |
40 ## axis ([1, 2, 3, 4], "square"); | |
41 ## @end example | |
42 ## | |
43 ## @noindent | |
44 ## forces a square aspect ratio. | |
45 ## | |
46 ## @noindent | |
47 ## The following options control the aspect ratio of the axes. | |
48 ## | |
49 ## @table @code | |
50 ## @item "square" | |
51 ## Force a square aspect ratio. | |
52 ## @item "equal" | |
53 ## Force x distance to equal y-distance. | |
54 ## @item "normal" | |
55 ## Restore the balance. | |
56 ## @end table | |
57 ## | |
58 ## @noindent | |
59 ## The following options control the way axis limits are interpreted. | |
60 ## | |
61 ## @table @code | |
62 ## @item "auto" | |
63 ## Set the specified axes to have nice limits around the data | |
64 ## or all if no axes are specified. | |
65 ## @item "manual" | |
66 ## Fix the current axes limits. | |
67 ## @item "tight" | |
68 ## Fix axes to the limits of the data (not implemented). | |
69 ## @end table | |
70 ## | |
71 ## @noindent | |
72 ## The option @code{"image"} is equivalent to @code{"tight"} and | |
73 ## @code{"equal"}. | |
74 ## | |
75 ## @noindent | |
76 ## The following options affect the appearance of tic marks. | |
77 ## | |
78 ## @table @code | |
79 ## @item "on" | |
80 ## Turn tic marks and labels on for all axes. | |
81 ## @item "off" | |
82 ## Turn tic marks off for all axes. | |
83 ## @item "tic[xyz]" | |
84 ## Turn tic marks on for all axes, or turns them on for the | |
85 ## specified axes and turns them off the remainder. | |
86 ## @item "label[xyz]" | |
87 ## Turn tic labels on for all axes, or turns them on for the | |
88 ## specified axes and turns them off for the remainder. | |
89 ## @item "nolabel" | |
90 ## Turn tic labels off for all axes. | |
91 ## @end table | |
92 ## Note, if there are no tic marks for an axis, there can be no labels. | |
93 ## | |
94 ## @noindent | |
95 ## The following options affect the direction of increasing values on | |
96 ## the axes. | |
97 ## | |
98 ## @table @code | |
99 ## @item "ij" | |
100 ## Reverse y-axis, so lower values are nearer the top. | |
101 ## @item "xy" | |
102 ## Restore y-axis, so higher values are nearer the top. | |
103 ## @end table | |
35 ## @end deftypefn | 104 ## @end deftypefn |
36 | 105 |
37 ## Author: jwe | 106 ## Author: jwe |
38 | 107 |
39 function curr_axis = axis (ax) | 108 function curr_axis = axis (ax, ...) |
40 | 109 |
41 ## This may not be correct if someone has used the gnuplot interface | 110 ## This may not be correct if someone has used the gnuplot interface |
42 ## directly... | 111 ## directly... |
43 | 112 |
44 global __current_axis__ = [-10, 10, -10, 10]; | 113 global __current_axis__ = [-10, 10, -10, 10]; |
45 | 114 |
46 if (nargin > 1) | 115 ## To return curr_axis properly, octave needs to take control of scaling. |
47 usage ("axis ([xmin, xmax, ymin, ymax, zmin, zmax])"); | 116 ## It isn't hard to compute good axis limits: |
48 endif | 117 ## scale = 10 ^ floor (log10 (max - min) - 1); |
118 ## r = scale * [floor (min / scale), ceil (max / scale)]; | |
119 ## However, with axis("manual") there is little need to know the current | |
120 ## limits. | |
49 | 121 |
50 if (nargin == 0) | 122 if (nargin == 0) |
51 gset autoscale; | 123 gset autoscale; |
52 curr_axis = __current_axis__; | 124 curr_axis = __current_axis__; |
125 | |
126 elseif (isstr (ax)) | |
127 ax = tolower (ax); | |
128 | |
129 ## 'matrix mode' to reverse the y-axis | |
130 if (strcmp (ax, "ij")) | |
131 gset yrange [] reverse; | |
132 elseif (strcmp (ax, "xy")) | |
133 gset yrange [] noreverse; | |
134 | |
135 ## aspect ratio | |
136 elseif (strcmp (ax, "image")) | |
137 gset size ratio -1; | |
138 gset autoscale; ## XXX FIXME XXX should be the same as "tight" | |
139 elseif (strcmp (ax, "equal")) | |
140 gset size ratio -1; | |
141 elseif (strcmp (ax, "square")) | |
142 gset size ratio 1; | |
143 elseif (strcmp (ax, "normal")) | |
144 gset size noratio; | |
145 | |
146 | |
147 ## axis limits | |
148 elseif (length (ax) >= 4 && strcmp (ax (1:4), "auto")) | |
149 if length (ax) > 4 | |
150 eval (["gset autoscale ", ax (5 : length (ax)), ";"]); | |
151 else | |
152 gset autoscale; | |
153 endif | |
154 elseif (strcmp (ax, "manual")) | |
155 ## fixes the axis limits, like axis(axis) should; | |
156 gset xrange [] writeback; | |
157 gset yrange [] writeback; | |
158 gset zrange [] writeback; | |
159 ## XXX FIXME XXX if writeback were set in plot, no need to replot here. | |
160 replot; | |
161 gset noautoscale x; | |
162 gset noautoscale y; | |
163 gset noautoscale z; | |
164 elseif (strcmp (ax, "tight")) | |
165 ## XXX FIXME XXX if tight, plot must set ranges to limits of the | |
166 ## all the data on the current plot, even if from a previous call. | |
167 ## Instead, just let gnuplot do as it likes. | |
168 gset autoscale; | |
169 | |
170 | |
171 ## tic marks | |
172 elseif (strcmp (ax, "on")) | |
173 gset xtics; | |
174 gset ytics; | |
175 gset ztics; | |
176 gset format; | |
177 elseif (strcmp (ax, "off")) | |
178 gset noxtics; | |
179 gset noytics; | |
180 gset noztics; | |
181 elseif (strcmp (ax, "tic")) | |
182 gset xtics; | |
183 gset ytics; | |
184 gset ztics; | |
185 elseif (length (ax) > 3 && strcmp (ax (1:3), "tic")) | |
186 if any (ax == "x") | |
187 gset xtics; | |
188 else | |
189 gset noxtics; | |
190 endif | |
191 if any (ax == "y") | |
192 gset ytics; | |
193 else | |
194 gset noytics; | |
195 endif | |
196 if any (ax == "z") | |
197 gset ztics; | |
198 else | |
199 gset noztics; | |
200 endif | |
201 elseif (strcmp (ax, "label")) | |
202 gset format; | |
203 elseif (strcmp (ax, "nolabel")) | |
204 gset format "\\0"; | |
205 elseif (length (ax) > 5 && strcmp (ax (1:5), "label")) | |
206 if any (ax == "x") | |
207 gset format x; | |
208 else | |
209 gset format x "\\0"; | |
210 endif | |
211 if any (ax == "y") | |
212 gset format y; | |
213 else | |
214 gset format y "\\0"; | |
215 endif | |
216 if any (ax == "z") | |
217 gset format z; | |
218 else | |
219 gset format z "\\0"; | |
220 endif | |
221 | |
222 else | |
223 warning (["unknown axis option '", ax, "'"]); | |
224 endif | |
225 | |
53 elseif (is_vector (ax)) | 226 elseif (is_vector (ax)) |
54 | 227 |
55 len = length (ax); | 228 len = length (ax); |
56 | 229 |
57 if (len != 2 && len != 4 && len != 6) | 230 if (len != 2 && len != 4 && len != 6) |
74 | 247 |
75 else | 248 else |
76 error ("axis: expecting no args, or a vector with 2, 4, or 6 elements"); | 249 error ("axis: expecting no args, or a vector with 2, 4, or 6 elements"); |
77 endif | 250 endif |
78 | 251 |
252 if (nargin > 1) | |
253 axis(all_va_args); | |
254 endif | |
79 endfunction | 255 endfunction |
256 | |
257 %!demo | |
258 %! t=0:0.01:2*pi; x=sin(t); | |
259 %! | |
260 %! subplot(221); title("normal plot"); | |
261 %! plot(t, x, ";;"); | |
262 %! | |
263 %! subplot(222); title("square plot"); | |
264 %! axis("square"); plot(t, x, ";;"); | |
265 %! | |
266 %! subplot(223); title("equal plot"); | |
267 %! axis("equal"); plot(t, x, ";;"); | |
268 %! | |
269 %! subplot(224); title("normal plot again"); | |
270 %! axis("normal"); plot(t, x, ";;"); | |
271 | |
272 %!demo | |
273 %! t=0:0.01:2*pi; x=sin(t); | |
274 %! | |
275 %! subplot(121); title("ij plot"); | |
276 %! axis("ij"); plot(t, x, ";;"); | |
277 %! | |
278 %! subplot(122); title("xy plot"); | |
279 %! axis("xy"); plot(t, x, ";;"); | |
280 | |
281 %!demo | |
282 %! t=0:0.01:2*pi; x=sin(t); | |
283 %! | |
284 %! subplot(331); title("x tics & labels"); | |
285 %! axis("ticx"); plot(t, x, ";;"); | |
286 %! | |
287 %! subplot(332); title("y tics & labels"); | |
288 %! axis("ticy"); plot(t, x, ";;"); | |
289 %! | |
290 %! subplot(334); title("x & y tics, x labels"); | |
291 %! axis("labelx","tic"); plot(t, x, ";;"); | |
292 %! | |
293 %! subplot(335); title("x & y tics, y labels"); | |
294 %! axis("labely","tic"); plot(t, x, ";;"); | |
295 %! | |
296 %! subplot(337); title("x tics, no labels"); | |
297 %! axis("nolabel","ticx"); plot(t, x, ";;"); | |
298 %! | |
299 %! subplot(338); title("y tics, no labels"); | |
300 %! axis("nolabel","ticy"); plot(t, x, ";;"); | |
301 %! | |
302 %! subplot(333); title("no tics or labels"); | |
303 %! axis("off"); plot(t, x, ";;"); | |
304 %! | |
305 %! subplot(336); title("all tics but no labels"); | |
306 %! axis("nolabel","tic"); plot(t, x, ";;"); | |
307 %! | |
308 %! subplot(339); title("all tics & labels"); | |
309 %! axis("on"); plot(t, x, ";;"); | |
310 | |
311 %!demo | |
312 %! t=0:0.01:2*pi; x=sin(t); | |
313 %! | |
314 %! subplot(321); title("axes at [0 3 0 1]") | |
315 %! axis([0,3,0,1]); plot(t, x, ";;"); | |
316 %! | |
317 %! subplot(322); title("auto"); | |
318 %! axis("auto"); plot(t, x, ";;"); | |
319 %! | |
320 %! subplot(323); title("manual"); | |
321 %! plot(t, x, ";sine [0:2pi];"); hold on; | |
322 %! axis("manual"); | |
323 %! plot(-3:3,-3:3, ";line (-3,-3)->(3,3);"); hold off; | |
324 %! | |
325 %! subplot(324); title("axes at [0 3 0 1], then autox"); | |
326 %! axis([0,3,0,1]); axis("autox"); | |
327 %! plot(t, x, ";sine [0:2pi];"); | |
328 %! | |
329 %! subplot(325); title("axes at [3 6 0 1], then autoy"); | |
330 %! axis([3,6,0,1]); axis("autoy"); | |
331 %! plot(t, x, ";sine [0:2p];"); | |
332 %! | |
333 %! subplot(326); title("tight"); | |
334 %! axis("tight"); plot(t, x, ";;"); | |
335 %! % The last plot should not have any whitespace outside the data | |
336 %! % limits, but "tight" isn't implemented yet. |