[graphics] better logarithmic plots
[scilab.git] / scilab / modules / graphics / macros / loglog.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 loglog(varargin)
9     [lhs,rhs]=argn(0);
10
11     if ~rhs
12        w=logspace(-2,2,1000);
13        s=%i*w;
14        g=[];
15        leg=[];
16        for alpha=logspace(-2,1,4);
17          g=[g;(1)./(s.^2+alpha*s+1)];
18        end
19        clf("reset")
20
21        loglog(w,abs(g));
22
23        title("$\LARGE \left|s^2/(s^2+\alpha s+1)\right|\mbox{ for }s=i\omega$")
24        xlabel("$\LARGE \omega$")
25        return
26     end
27
28     current_figure = gcf();
29     cur_draw_mode = current_figure.immediate_drawing;
30     current_figure.immediate_drawing = "off";
31
32     ok = isempty(gca().children) || and(gca().data_bounds([1 3]) > 0);
33     set(gca(),"log_flags","nn")
34     try
35         plot(varargin(:))
36         if ok
37             set(gca(),"log_flags","ll")
38         end
39     catch
40         current_figure.immediate_drawing = cur_draw_mode;
41         error(lasterror(%t))
42     end
43
44     current_figure.immediate_drawing = cur_draw_mode;
45 endfunction