]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/loglog.m
update packages
[CreaPhase.git] / octave_packages / m / plot / loglog.m
1 ## Copyright (C) 1993-2012 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 3 of the License, or (at
8 ## your option) 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, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn  {Function File} {} loglog (@var{y})
21 ## @deftypefnx {Function File} {} loglog (@var{x}, @var{y})
22 ## @deftypefnx {Function File} {} loglog (@var{x}, @var{y}, @var{property}, @var{value}, @dots{})
23 ## @deftypefnx {Function File} {} loglog (@var{x}, @var{y}, @var{fmt})
24 ## @deftypefnx {Function File} {} loglog (@var{h}, @dots{})
25 ## @deftypefnx {Function File} {@var{h} =} loglog (@dots{})
26 ## Produce a two-dimensional plot using log scales for both axes.  See
27 ## the documentation of @code{plot} for a description of the arguments
28 ## that @code{loglog} will accept.
29 ##
30 ## The optional return value @var{h} is a graphics handle to the created plot.
31 ## @seealso{plot, semilogx, semilogy}
32 ## @end deftypefn
33
34 ## Author: jwe
35
36 function retval = loglog (varargin)
37
38   [h, varargin, nargs] = __plt_get_axis_arg__ ("loglog", varargin{:});
39
40   if (nargs < 1)
41     print_usage();
42   endif
43
44   oldh = gca ();
45   unwind_protect
46     axes (h);
47     newplot ();
48
49     set (h, "xscale", "log", "yscale", "log");
50     if (any( strcmp (get (gca, "nextplot"), {"new", "replace"})))
51       set (h, "xminortick", "on", "yminortick", "on");
52     endif
53
54     tmp = __plt__ ("loglog", h, varargin{:});
55
56     if (nargout > 0)
57       retval = tmp;
58     endif
59   unwind_protect_cleanup
60     axes (oldh);
61   end_unwind_protect
62
63 endfunction
64
65 %!demo
66 %! clf ();
67 %! t = 1:0.01:10;
68 %! x = sort ((t .* (1 + rand (size (t)))) .^ 2);
69 %! y = ((t .* (1 + rand (size (t)))) .^ 2);
70 %! loglog (x, y);
71
72 %!demo
73 %! clf ();
74 %! a = logspace (-5, 1, 10);
75 %! b =-logspace (-5, 1, 10);
76 %!
77 %! subplot (1, 2, 1)
78 %! loglog (a, b)
79 %! xlabel ('loglog (a, b)')
80 %!
81 %! subplot (1, 2, 2)
82 %! loglog (a, abs (b))
83 %! set (gca, 'ydir', 'reverse')
84 %! xlabel ('loglog (a, abs (b))')
85
86 %!test
87 %! hf = figure ("visible", "off");
88 %! unwind_protect
89 %!   a = logspace (-5, 1, 10);
90 %!   b = logspace (-5, 1, 10);
91 %!   loglog (a, b)
92 %!   assert (get (gca, "yscale"), "log");
93 %!   assert (get (gca, "xscale"), "log");
94 %! unwind_protect_cleanup
95 %! close (hf);
96 %! end_unwind_protect
97
98 %!test
99 %! hf = figure ("visible", "off");
100 %! unwind_protect
101 %!   a = logspace (-5, 1, 10);
102 %!   b =-logspace (-5, 1, 10);
103 %!   loglog (a, b)
104 %!   axis tight
105 %!   assert (all (get (gca, "ytick") < 0));
106 %! unwind_protect_cleanup
107 %! close (hf);
108 %! end_unwind_protect
109