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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, 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 ## |
4945
|
29 ## Without any arguments, @code{axis} turns autoscaling on. |
|
30 ## |
|
31 ## With one output argument, @code{x=axis} returns the current axes |
|
32 ## (this is not yet implemented for automatic axes). |
3667
|
33 ## |
3668
|
34 ## The vector argument specifying limits is optional, and additional |
|
35 ## string arguments may be used to specify various axis properties. For |
3667
|
36 ## example, |
|
37 ## |
|
38 ## @example |
|
39 ## axis ([1, 2, 3, 4], "square"); |
|
40 ## @end example |
|
41 ## |
|
42 ## @noindent |
3668
|
43 ## forces a square aspect ratio, and |
|
44 ## |
|
45 ## @example |
|
46 ## axis ("labely", "tic"); |
|
47 ## @end example |
|
48 ## |
|
49 ## @noindent |
|
50 ## turns tic marks on for all axes and tic mark labels on for the y-axis |
|
51 ## only. |
3667
|
52 ## |
|
53 ## @noindent |
|
54 ## The following options control the aspect ratio of the axes. |
|
55 ## |
|
56 ## @table @code |
|
57 ## @item "square" |
|
58 ## Force a square aspect ratio. |
|
59 ## @item "equal" |
|
60 ## Force x distance to equal y-distance. |
|
61 ## @item "normal" |
|
62 ## Restore the balance. |
|
63 ## @end table |
|
64 ## |
|
65 ## @noindent |
|
66 ## The following options control the way axis limits are interpreted. |
|
67 ## |
|
68 ## @table @code |
|
69 ## @item "auto" |
|
70 ## Set the specified axes to have nice limits around the data |
|
71 ## or all if no axes are specified. |
|
72 ## @item "manual" |
|
73 ## Fix the current axes limits. |
|
74 ## @item "tight" |
|
75 ## Fix axes to the limits of the data (not implemented). |
|
76 ## @end table |
|
77 ## |
|
78 ## @noindent |
|
79 ## The option @code{"image"} is equivalent to @code{"tight"} and |
|
80 ## @code{"equal"}. |
|
81 ## |
|
82 ## @noindent |
|
83 ## The following options affect the appearance of tic marks. |
|
84 ## |
|
85 ## @table @code |
|
86 ## @item "on" |
|
87 ## Turn tic marks and labels on for all axes. |
|
88 ## @item "off" |
|
89 ## Turn tic marks off for all axes. |
|
90 ## @item "tic[xyz]" |
3668
|
91 ## Turn tic marks on for all axes, or turn them on for the |
|
92 ## specified axes and off for the remainder. |
3667
|
93 ## @item "label[xyz]" |
3668
|
94 ## Turn tic labels on for all axes, or turn them on for the |
|
95 ## specified axes and off for the remainder. |
3667
|
96 ## @item "nolabel" |
|
97 ## Turn tic labels off for all axes. |
|
98 ## @end table |
|
99 ## Note, if there are no tic marks for an axis, there can be no labels. |
|
100 ## |
|
101 ## @noindent |
|
102 ## The following options affect the direction of increasing values on |
|
103 ## the axes. |
|
104 ## |
|
105 ## @table @code |
|
106 ## @item "ij" |
|
107 ## Reverse y-axis, so lower values are nearer the top. |
|
108 ## @item "xy" |
|
109 ## Restore y-axis, so higher values are nearer the top. |
|
110 ## @end table |
4945
|
111 ## |
3368
|
112 ## @end deftypefn |
590
|
113 |
2314
|
114 ## Author: jwe |
|
115 |
5561
|
116 ## PKG_ADD: mark_as_command axis |
5560
|
117 |
3979
|
118 function curr_axis = axis (ax, varargin) |
590
|
119 |
6257
|
120 ca = gca (); |
590
|
121 |
595
|
122 if (nargin == 0) |
4945
|
123 if (nargout == 0) |
6257
|
124 set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto"); |
4945
|
125 else |
6257
|
126 xlim = get (ca, "xlim"); |
|
127 ylim = get (ca, "ylim"); |
|
128 zlim = get (ca, "zlim"); |
|
129 curr_axis = [xlim, ylim, zlim]; |
4945
|
130 endif |
3667
|
131 |
5443
|
132 elseif (ischar (ax)) |
3667
|
133 ax = tolower (ax); |
4340
|
134 len = length (ax); |
3667
|
135 |
|
136 ## 'matrix mode' to reverse the y-axis |
|
137 if (strcmp (ax, "ij")) |
6257
|
138 set (ca, "ydir", "reverse"); |
3667
|
139 elseif (strcmp (ax, "xy")) |
6257
|
140 set (ca, "ydir", "normal"); |
3667
|
141 |
|
142 ## aspect ratio |
|
143 elseif (strcmp (ax, "image")) |
6257
|
144 set (ca, "dataaspectratio", [1, 1, 1]); |
|
145 ## FIXME should be the same as "tight" |
|
146 set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto"); |
|
147 elseif (strcmp (ax, "equal") || strcmp (ax, "square")) |
|
148 set (ca, "dataaspectratio", [1, 1, 1]); |
3667
|
149 elseif (strcmp (ax, "normal")) |
6257
|
150 set (ca, "dataaspectratiomode", "auto"); |
3667
|
151 |
|
152 ## axis limits |
4340
|
153 elseif (len >= 4 && strcmp (ax(1:4), "auto")) |
|
154 if (len > 4) |
6257
|
155 if (any (ax == "x")) |
|
156 set (ca, "xlimmode", "auto"); |
|
157 endif |
|
158 if (any (ax == "y")) |
|
159 set (ca, "ylimmode", "auto"); |
|
160 endif |
|
161 if (any (ax == "z")) |
|
162 set (ca, "zlimmode", "auto"); |
|
163 endif |
3667
|
164 else |
6257
|
165 set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto"); |
3667
|
166 endif |
|
167 elseif (strcmp (ax, "manual")) |
|
168 ## fixes the axis limits, like axis(axis) should; |
6257
|
169 set (ca, "xlimmode", "manual", "ylimmode", "manual", "zlimmode", "manual"); |
3667
|
170 elseif (strcmp (ax, "tight")) |
5775
|
171 ## FIXME if tight, plot must set ranges to limits of the |
3667
|
172 ## all the data on the current plot, even if from a previous call. |
|
173 ## Instead, just let gnuplot do as it likes. |
6257
|
174 set (ca, "xlimmode", "auto", "ylimmode", "auto", "zlimmode", "auto"); |
3667
|
175 |
|
176 ## tic marks |
6257
|
177 elseif (strcmp (ax, "on") || strcmp (ax, "tic")) |
|
178 set (ca, "xtickmode", "auto", "ytickmode", "auto", "ztickmode", "auto"); |
|
179 set (ca, "xticklabelmode", "auto", "yticklabelmode", "auto", |
|
180 "zticklabelmode", "auto"); |
3667
|
181 elseif (strcmp (ax, "off")) |
6257
|
182 set (ca, "xtick", [], "ytick", [], "ztick", []); |
4340
|
183 elseif (len > 3 && strcmp (ax(1:3), "tic")) |
|
184 if (any (ax == "x")) |
6257
|
185 set (ca, "xtickmode", "auto"); |
3667
|
186 else |
6257
|
187 set (ca, "xtick", []); |
3667
|
188 endif |
4340
|
189 if (any (ax == "y")) |
6257
|
190 set (ca, "ytickmode", "auto"); |
3667
|
191 else |
6257
|
192 set (ca, "ytick", []); |
3667
|
193 endif |
4340
|
194 if (any (ax == "z")) |
6257
|
195 set (ca, "ztickmode", "auto"); |
3667
|
196 else |
6257
|
197 set (ca, "ztick", []); |
3667
|
198 endif |
|
199 elseif (strcmp (ax, "label")) |
6257
|
200 set (ca, "xticklabelmode", "auto", "yticklabelmode", "auto", |
|
201 "zticklabelmode", "auto"); |
3667
|
202 elseif (strcmp (ax, "nolabel")) |
6257
|
203 set (ca, "xticklabel", "", "yticklabel", "", "zticklabel", ""); |
4340
|
204 elseif (len > 5 && strcmp (ax(1:5), "label")) |
|
205 if (any (ax == "x")) |
6257
|
206 set (ca, "xticklabelmode", "auto"); |
3667
|
207 else |
6257
|
208 set (ca, "xticklabel", ""); |
3667
|
209 endif |
4340
|
210 if (any (ax == "y")) |
6257
|
211 set (ca, "yticklabelmode", "auto"); |
3667
|
212 else |
6257
|
213 set (ca, "yticklabel", ""); |
3667
|
214 endif |
4340
|
215 if (any (ax == "z")) |
6257
|
216 set (ca, "zticklabelmode", "auto"); |
3667
|
217 else |
6257
|
218 set (ca, "zticklabel", ""); |
3667
|
219 endif |
|
220 |
|
221 else |
4259
|
222 warning ("unknown axis option '%s'", ax); |
3667
|
223 endif |
|
224 |
4030
|
225 elseif (isvector (ax)) |
590
|
226 |
|
227 len = length (ax); |
|
228 |
|
229 if (len != 2 && len != 4 && len != 6) |
|
230 error ("axis: expecting vector with 2, 4, or 6 elements"); |
|
231 endif |
|
232 |
5627
|
233 for i = 1:2:len |
|
234 if (ax(i) == ax(i+1)) |
|
235 error ("axis: limits(%d) cannot equal limits(%d)", i, i+1); |
|
236 endif |
|
237 endfor |
|
238 |
590
|
239 if (len > 1) |
6257
|
240 set (ca, "xlim", [ax(1), ax(2)]); |
590
|
241 endif |
|
242 |
|
243 if (len > 3) |
6257
|
244 set (ca, "ylim", [ax(3), ax(4)]); |
590
|
245 endif |
|
246 |
|
247 if (len > 5) |
6257
|
248 set (ca, "zlim", [ax(5), ax(6)]); |
590
|
249 endif |
|
250 |
|
251 else |
595
|
252 error ("axis: expecting no args, or a vector with 2, 4, or 6 elements"); |
590
|
253 endif |
|
254 |
3667
|
255 if (nargin > 1) |
3979
|
256 axis (varargin{:}); |
3667
|
257 endif |
6447
|
258 |
590
|
259 endfunction |
3667
|
260 |
|
261 %!demo |
|
262 %! t=0:0.01:2*pi; x=sin(t); |
|
263 %! |
|
264 %! subplot(221); title("normal plot"); |
|
265 %! plot(t, x, ";;"); |
|
266 %! |
|
267 %! subplot(222); title("square plot"); |
|
268 %! axis("square"); plot(t, x, ";;"); |
|
269 %! |
|
270 %! subplot(223); title("equal plot"); |
|
271 %! axis("equal"); plot(t, x, ";;"); |
|
272 %! |
|
273 %! subplot(224); title("normal plot again"); |
|
274 %! axis("normal"); plot(t, x, ";;"); |
|
275 |
|
276 %!demo |
|
277 %! t=0:0.01:2*pi; x=sin(t); |
|
278 %! |
|
279 %! subplot(121); title("ij plot"); |
|
280 %! axis("ij"); plot(t, x, ";;"); |
|
281 %! |
|
282 %! subplot(122); title("xy plot"); |
|
283 %! axis("xy"); plot(t, x, ";;"); |
|
284 |
|
285 %!demo |
|
286 %! t=0:0.01:2*pi; x=sin(t); |
|
287 %! |
|
288 %! subplot(331); title("x tics & labels"); |
|
289 %! axis("ticx"); plot(t, x, ";;"); |
|
290 %! |
|
291 %! subplot(332); title("y tics & labels"); |
|
292 %! axis("ticy"); plot(t, x, ";;"); |
|
293 %! |
|
294 %! subplot(334); title("x & y tics, x labels"); |
|
295 %! axis("labelx","tic"); plot(t, x, ";;"); |
|
296 %! |
|
297 %! subplot(335); title("x & y tics, y labels"); |
|
298 %! axis("labely","tic"); plot(t, x, ";;"); |
|
299 %! |
|
300 %! subplot(337); title("x tics, no labels"); |
|
301 %! axis("nolabel","ticx"); plot(t, x, ";;"); |
|
302 %! |
|
303 %! subplot(338); title("y tics, no labels"); |
|
304 %! axis("nolabel","ticy"); plot(t, x, ";;"); |
|
305 %! |
|
306 %! subplot(333); title("no tics or labels"); |
|
307 %! axis("off"); plot(t, x, ";;"); |
|
308 %! |
|
309 %! subplot(336); title("all tics but no labels"); |
|
310 %! axis("nolabel","tic"); plot(t, x, ";;"); |
|
311 %! |
|
312 %! subplot(339); title("all tics & labels"); |
|
313 %! axis("on"); plot(t, x, ";;"); |
|
314 |
|
315 %!demo |
|
316 %! t=0:0.01:2*pi; x=sin(t); |
|
317 %! |
|
318 %! subplot(321); title("axes at [0 3 0 1]") |
|
319 %! axis([0,3,0,1]); plot(t, x, ";;"); |
|
320 %! |
|
321 %! subplot(322); title("auto"); |
|
322 %! axis("auto"); plot(t, x, ";;"); |
|
323 %! |
|
324 %! subplot(323); title("manual"); |
|
325 %! plot(t, x, ";sine [0:2pi];"); hold on; |
|
326 %! axis("manual"); |
|
327 %! plot(-3:3,-3:3, ";line (-3,-3)->(3,3);"); hold off; |
|
328 %! |
|
329 %! subplot(324); title("axes at [0 3 0 1], then autox"); |
|
330 %! axis([0,3,0,1]); axis("autox"); |
|
331 %! plot(t, x, ";sine [0:2pi];"); |
|
332 %! |
|
333 %! subplot(325); title("axes at [3 6 0 1], then autoy"); |
|
334 %! axis([3,6,0,1]); axis("autoy"); |
|
335 %! plot(t, x, ";sine [0:2p];"); |
|
336 %! |
|
337 %! subplot(326); title("tight"); |
|
338 %! axis("tight"); plot(t, x, ";;"); |
|
339 %! % The last plot should not have any whitespace outside the data |
|
340 %! % limits, but "tight" isn't implemented yet. |