2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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. |
590
|
19 |
3368
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} axis (@var{limits}) |
3667
|
22 ## Set axis limits for plots. |
3426
|
23 ## |
3368
|
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 |
|
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. |
3426
|
28 ## |
3368
|
29 ## If your plot is already drawn, then you need to use @code{replot} before |
|
30 ## the new axis limits will take effect. You can get this to happen |
|
31 ## automatically by setting the built-in variable @code{automatic_replot} |
|
32 ## to a nonzero value. |
3667
|
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 |
3368
|
104 ## @end deftypefn |
590
|
105 |
2314
|
106 ## Author: jwe |
|
107 |
3667
|
108 function curr_axis = axis (ax, ...) |
590
|
109 |
2303
|
110 ## This may not be correct if someone has used the gnuplot interface |
|
111 ## directly... |
1610
|
112 |
3106
|
113 global __current_axis__ = [-10, 10, -10, 10]; |
1610
|
114 |
3667
|
115 ## To return curr_axis properly, octave needs to take control of scaling. |
|
116 ## It isn't hard to compute good axis limits: |
|
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. |
590
|
121 |
595
|
122 if (nargin == 0) |
2520
|
123 gset autoscale; |
1610
|
124 curr_axis = __current_axis__; |
3667
|
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 |
595
|
226 elseif (is_vector (ax)) |
590
|
227 |
|
228 len = length (ax); |
|
229 |
|
230 if (len != 2 && len != 4 && len != 6) |
|
231 error ("axis: expecting vector with 2, 4, or 6 elements"); |
|
232 endif |
|
233 |
1610
|
234 __current_axis__ = reshape (ax, 1, len); |
|
235 |
590
|
236 if (len > 1) |
2520
|
237 eval (sprintf ("gset xrange [%g:%g];", ax (1), ax (2))); |
590
|
238 endif |
|
239 |
|
240 if (len > 3) |
2520
|
241 eval (sprintf ("gset yrange [%g:%g];", ax (3), ax (4))); |
590
|
242 endif |
|
243 |
|
244 if (len > 5) |
2520
|
245 eval (sprintf ("gset zrange [%g:%g];", ax (5), ax (6))); |
590
|
246 endif |
|
247 |
|
248 else |
595
|
249 error ("axis: expecting no args, or a vector with 2, 4, or 6 elements"); |
590
|
250 endif |
|
251 |
3667
|
252 if (nargin > 1) |
|
253 axis(all_va_args); |
|
254 endif |
590
|
255 endfunction |
3667
|
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. |