]> Creatis software - CreaPhase.git/blob - octave_packages/m/plot/semilogx.m
update packages
[CreaPhase.git] / octave_packages / m / plot / semilogx.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} {} semilogx (@var{y})
21 ## @deftypefnx {Function File} {} semilogx (@var{x}, @var{y})
22 ## @deftypefnx {Function File} {} semilogx (@var{x}, @var{y}, @var{property}, @var{value}, @dots{})
23 ## @deftypefnx {Function File} {} semilogx (@var{x}, @var{y}, @var{fmt})
24 ## @deftypefnx {Function File} {} semilogx (@var{h}, @dots{})
25 ## @deftypefnx {Function File} {@var{h} =} semilogx (@dots{})
26 ## Produce a two-dimensional plot using a logarithmic scale for the @var{x}
27 ## axis.  See the documentation of @code{plot} for a description of the
28 ## arguments that @code{semilogx} will accept.
29 ## 
30 ## The optional return value @var{h} is a graphics handle to the created plot.
31 ## @seealso{plot, semilogy, loglog}
32 ## @end deftypefn
33
34 ## Author: jwe
35
36 function retval = semilogx (varargin)
37
38   [h, varargin, nargs] = __plt_get_axis_arg__ ("semilogx", 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");
50     if (any( strcmp (get (gca, "nextplot"), {"new", "replace"})))
51       set (h, "xminortick", "on");
52     endif
53
54     tmp = __plt__ ("semilogx", 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
66 %!demo
67 %! clf ();
68 %! x = 1:0.01:10;
69 %! y = (x .* (1 + rand (size (x)))) .^ 2;
70 %! semilogx (y, x);
71
72 %!demo
73 %! clf ();
74 %! x = logspace (-5, 1, 10);
75 %! y = logspace (-5, 1, 10);
76 %!
77 %! subplot (1, 2, 1);
78 %! semilogx (x, y);
79 %! xlabel ("semilogx (x, y)");
80 %!
81 %! subplot (1, 2, 2);
82 %! semilogx (-x, y);
83 %! xlabel ("semilogx (-x, y)");
84
85 %!demo
86 %! clf ();
87 %! x = logspace (-5, 1, 10);
88 %! y = logspace (-5, 1, 10);
89 %!
90 %! subplot (1, 2, 1);
91 %! semilogx (x, y);
92 %! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition")
93 %! xlabel ({"semilogx (x, y)", "xdir = reversed"})
94 %!
95 %! subplot (1, 2, 2);
96 %! semilogx (-x, y);
97 %! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition");
98 %! xlabel ({"semilogx (-x, y)", "xdir = reversed"});
99
100 %!test
101 %! hf = figure ("visible", "off");
102 %! unwind_protect
103 %!   a = logspace (-5, 1, 10);
104 %!   b = logspace (-5, 1, 10);
105 %!   semilogx (a, b)
106 %!   assert (get (gca, "xscale"), "log");
107 %!   assert (get (gca, "yscale"), "linear");
108 %! unwind_protect_cleanup
109 %!   close (hf);
110 %! end_unwind_protect
111
112 %!test
113 %! hf = figure ("visible", "off");
114 %! unwind_protect
115 %!   a =-logspace (-5, 1, 10);
116 %!   b = logspace (-5, 1, 10);
117 %!   semilogx (a, b);
118 %!   axis tight;
119 %!   assert (all (get (gca, "xtick") < 0));
120 %! unwind_protect_cleanup
121 %!   close (hf);
122 %! end_unwind_protect
123