[graphics] better logarithmic plots
[scilab.git] / scilab / modules / graphics / macros / semilogx.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2020 - St├ęphane MOTTELET
3 //
4 // This file is hereby licensed under the terms of the GNU GPL v2.0,
5 // For more information, see the COPYING file which you should have received
6 // along with this program.
7
8 function semilogx(varargin)
9     [lhs,rhs]=argn(0);
10
11     if ~rhs
12        w=logspace(-2,2,1000);
13        s=%i*w;
14        g=1../(s.^2+s+1);
15        clf("reset")
16
17        semilogx(w,abs(g));
18
19             title("$\LARGE \left|1/(s^2+s+1)\right|\mbox{ for }s=i\omega$")
20        xlabel("$\LARGE \omega$")
21        return
22     end
23
24     current_figure = gcf();
25     cur_draw_mode = current_figure.immediate_drawing;
26     current_figure.immediate_drawing = "off";
27
28     ok = isempty(gca().children) || gca().data_bounds(1) > 0;
29     set(gca(),"log_flags","nn")
30     try
31         plot(varargin(:))
32         if ok
33             set(gca(),"log_flags","ln")
34         end
35     catch
36         current_figure.immediate_drawing = cur_draw_mode;
37         error(lasterror(%t))
38     end
39     current_figure.immediate_drawing = cur_draw_mode;
40
41 endfunction