/usr/share/doc/libplplot12/examples/ocaml/x04.ml is in libplplot-dev 5.10.0+dfsg2-0.1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | (* $Id: x04.ml 12313 2013-05-01 01:12:18Z hezekiahcarty $
Log plot demo.
*)
open Plplot
let pi = atan 1.0 *. 4.0
(*--------------------------------------------------------------------------*\
* plot1
*
* Log-linear plot.
\*--------------------------------------------------------------------------*)
let plot1 plot_type =
pladv 0;
(* Set up data for log plot *)
let f0 = 1.0 in
let freql = Array.init 101 (fun i -> -2.0 +. float_of_int i /. 20.0) in
let freq = Array.map (fun x -> 10.0**x) freql in
let ampl =
Array.map (
fun x -> 20.0 *. log10 (1.0 /. sqrt (1.0 +. (x /. f0)**2.0))
) freq
in
let phase =
Array.map (fun x -> -.(180.0 /. pi) *. atan (x /. f0)) freq
in
plvpor 0.15 0.85 0.1 0.9;
plwind (-2.0) 3.0 (-80.0) 0.0;
(* Try different axis and labelling styles. *)
plcol0 1;
let () =
match plot_type with
0 ->
plbox "bclnst" 0.0 0 "bnstv" 0.0 0;
| 1 ->
plbox "bcfghlnst" 0.0 0 "bcghnstv" 0.0 0;
| _ -> failwith "Bad plot type specified"
in
(* Plot ampl vs freq *)
plcol0 2;
plline freql ampl;
plcol0 2;
plptex 1.6 (-30.0) 1.0 (-20.0) 0.5 "-20 dB/decade";
(* Put labels on *)
plcol0 1;
plmtex "b" 3.2 0.5 0.5 "Frequency";
plmtex "t" 2.0 0.5 0.5 "Single Pole Low-Pass Filter";
plcol0 2;
plmtex "l" 5.0 0.5 0.5 "Amplitude (dB)";
(* For the gridless case, put phase vs freq on same plot *)
if plot_type = 0 then (
plcol0 1;
plwind (-2.0) 3.0 (-100.0) 0.0;
plbox "" 0.0 0 "cmstv" 30.0 3;
plcol0 3;
plline freql phase;
plstring freql phase "*";
plcol0 3;
plmtex "r" 5.0 0.5 0.5 "Phase shift (degrees)";
(* Draw a legend *)
(* First legend entry. *)
let opt_array = [| [PL_LEGEND_LINE]; [PL_LEGEND_LINE; PL_LEGEND_SYMBOL] |] in
let text_colors = [| 2; 3 |] in
let text = [| "Amplitude"; "Phase shift" |] in
let line_colors = [| 2; 3 |] in
let line_styles = [| 1; 1 |] in
let line_widths = [| 1.0; 1.0 |] in
(* note from the above opt_array the first symbol (and box) indices
do not matter *)
(* Second legend entry. *)
let symbol_colors = [| 0; 3 |] in
let symbol_scales = [| 0.0; 1.0 |] in
let symbol_numbers = [| 0; 4 |] in
let symbols = [| ""; "*" |] in
(* from the above opt_arrays we can completely ignore everything
to do with boxes *)
plscol0a 15 32 32 32 0.70;
ignore (
pllegend [PL_LEGEND_BACKGROUND; PL_LEGEND_BOUNDING_BOX] []
0.0 0.0 0.1 15
1 1 0 0
opt_array
1.0 1.0 2.0
1.0 text_colors text
[||] [||] [||] [||]
line_colors line_styles line_widths
symbol_colors symbol_scales symbol_numbers symbols
);
()
)
else if plot_type = 1 then (
(* Draw a legend *)
(* First legend entry. *)
let opt_array = [| [PL_LEGEND_LINE] |] in
let text_colors = [| 2 |] in
let text = [| "Amplitude" |] in
let line_colors = [| 2 |] in
let line_styles = [| 1 |] in
let line_widths = [| 1.0 |] in
(* note from the above opt_array the first symbol (and box) indices
do not matter *)
(* from the above opt_arrays we can completely ignore everything
to do with boxes and symbols *)
plscol0a 15 32 32 32 0.70;
ignore (
pllegend [PL_LEGEND_BACKGROUND; PL_LEGEND_BOUNDING_BOX] []
0.0 0.0 0.1 15
1 1 0 0
opt_array
1.0 1.0 2.0
1.0 text_colors text
[||] [||] [||] [||]
line_colors line_styles line_widths
[||] [||] [||] [||]
);
()
)
(*--------------------------------------------------------------------------*\
* Illustration of logarithmic axes, and redefinition of window.
\*--------------------------------------------------------------------------*)
let () =
(* Parse and process command line arguments *)
plparseopts Sys.argv [PL_PARSE_FULL];
(* Initialize plplot *)
plinit();
plfont 2;
(* Make log plots using two different styles. *)
plot1 0;
plot1 1;
plend ();
()
|