1######################################################################## 2## 3## Copyright (C) 1993-2021 The Octave Project Developers 4## 5## See the file COPYRIGHT.md in the top-level directory of this 6## distribution or <https://octave.org/copyright/>. 7## 8## This file is part of Octave. 9## 10## Octave is free software: you can redistribute it and/or modify it 11## under the terms of the GNU General Public License as published by 12## the Free Software Foundation, either version 3 of the License, or 13## (at your option) any later version. 14## 15## Octave is distributed in the hope that it will be useful, but 16## WITHOUT ANY WARRANTY; without even the implied warranty of 17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18## GNU General Public License for more details. 19## 20## You should have received a copy of the GNU General Public License 21## along with Octave; see the file COPYING. If not, see 22## <https://www.gnu.org/licenses/>. 23## 24######################################################################## 25 26## -*- texinfo -*- 27## @deftypefn {} {} semilogx (@var{y}) 28## @deftypefnx {} {} semilogx (@var{x}, @var{y}) 29## @deftypefnx {} {} semilogx (@var{x}, @var{y}, @var{property}, @var{value}, @dots{}) 30## @deftypefnx {} {} semilogx (@var{x}, @var{y}, @var{fmt}) 31## @deftypefnx {} {} semilogx (@var{hax}, @dots{}) 32## @deftypefnx {} {@var{h} =} semilogx (@dots{}) 33## Produce a 2-D plot using a logarithmic scale for the x-axis. 34## 35## See the documentation of @code{plot} for a description of the 36## arguments that @code{semilogx} will accept. 37## 38## If the first argument @var{hax} is an axes handle, then plot into this axes, 39## rather than the current axes returned by @code{gca}. 40## 41## The optional return value @var{h} is a graphics handle to the created plot. 42## @seealso{plot, semilogy, loglog} 43## @end deftypefn 44 45function h = semilogx (varargin) 46 47 [hax, varargin, nargs] = __plt_get_axis_arg__ ("semilogx", varargin{:}); 48 49 if (nargs < 1) 50 print_usage (); 51 endif 52 53 oldfig = []; 54 if (! isempty (hax)) 55 oldfig = get (0, "currentfigure"); 56 endif 57 unwind_protect 58 hax = newplot (hax); 59 60 set (hax, "xscale", "log"); 61 if (! ishold ()) 62 set (hax, "xminortick", "on", "box", "on"); 63 endif 64 65 htmp = __plt__ ("semilogx", hax, varargin{:}); 66 67 unwind_protect_cleanup 68 if (! isempty (oldfig)) 69 set (0, "currentfigure", oldfig); 70 endif 71 end_unwind_protect 72 73 if (nargout > 0) 74 h = htmp; 75 endif 76 77endfunction 78 79 80%!demo 81%! clf; 82%! x = 1:0.01:10; 83%! y = (x .* (1 + rand (size (x)))) .^ 2; 84%! semilogx (y, x); 85%! title ({"semilogx() plot", "X-axis is logarithmic"}); 86 87%!demo 88%! clf; 89%! x = logspace (-5, 1, 10); 90%! y = logspace (-5, 1, 10); 91%! 92%! subplot (1,2,1); 93%! semilogx (x, y); 94%! title ("semilogx (x, y)"); 95%! 96%! subplot (1,2,2); 97%! semilogx (-x, y); 98%! title ("semilogx (-x, y)"); 99 100%!demo 101%! clf; 102%! x = logspace (-5, 1, 10); 103%! y = logspace (-5, 1, 10); 104%! 105%! subplot (1,2,1); 106%! semilogx (x, y); 107%! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition"); 108%! title ({"semilogx (x, y)", "xdir = reversed"}); 109%! 110%! subplot (1,2,2); 111%! semilogx (-x, y); 112%! set (gca, "xdir", "reverse", "activepositionproperty", "outerposition"); 113%! title ({"semilogx (-x, y)", "xdir = reversed"}); 114 115%!test 116%! hf = figure ("visible", "off"); 117%! unwind_protect 118%! a = logspace (-5, 1, 10); 119%! b = logspace (-5, 1, 10); 120%! semilogx (a, b); 121%! assert (get (gca, "xscale"), "log"); 122%! assert (get (gca, "yscale"), "linear"); 123%! unwind_protect_cleanup 124%! close (hf); 125%! end_unwind_protect 126 127%!test 128%! hf = figure ("visible", "off"); 129%! unwind_protect 130%! a =-logspace (-5, 1, 10); 131%! b = logspace (-5, 1, 10); 132%! semilogx (a, b); 133%! axis tight; 134%! assert (all (get (gca, "xtick") < 0)); 135%! unwind_protect_cleanup 136%! close (hf); 137%! end_unwind_protect 138