Guillaume Hennequin avatar Guillaume Hennequin committed a1bd553

reindented code

Comments (0)

Files changed (2)

-
 let _ = Random.self_init ()
-
+  
 (* generate some random data *)
 let unif = Array.init 1000 (fun _ -> Random.float 1.)
-
+  
 (* simple y-vector plot *)
-let _ = 
+let _ =
   let f = Gp.figure() in
   Gp.send ["set xlabel 'trial #'";
-	   "set ylabel 'value";
-	   "set title 'random stuff'";
-	   "set xtics 0,200,1000";
-	   "set ytics 0,0.5,1"] f;
+    "set ylabel 'value";
+    "set title 'random stuff'";
+    "set xtics 0,200,1000";
+  "set ytics 0,0.5,1"] f;
   Gp.plot [[unif],"w p pt 7 lc 7 ps 0.2"] f;
   Gp.close f
-	   
+  
 (* double y-vector plot, quick shortcut *)
 let expo = Array.map exp unif
-let _ = Gp.quick (Gp.plot [[unif],"w p pt 7 lc 7 ps 0.1";
-			   [expo],"w p pt 7 lc 1 ps 0.1"])
+let _ = Gp.quick (Gp.plot
+    [ [unif],"w p pt 7 lc 7 ps 0.1";
+      [expo],"w p pt 7 lc 1 ps 0.1" ])
   
-
+  
 (* simple xy relationship plot *)
 let x = Array.init 1000 float
 let y1 = Array.map (fun z -> sin (2. *. 3.1415 *. z /. 200.)) x
 let y2 = Array.map (fun z -> cos (2. *. 3.1415 *. z /. 200.)) x
-let _ = 
+let _ =
   let f = Gp.figure() in
   Gp.plot [[x;y1],"w l ls 1";
-	   [x;y2],"w l ls 3"] f;
+    [x;y2],"w l ls 3"] f;
   Gp.close f
-
+  
 (* smooth histogram *)
 let _ =
   let f = Gp.figure() in
   Gp.send ["unset ytics"] f;
   Gp.plot [[unif],"u 1:0:(0.01) w l ls 7 smooth kdensity"] f;
   Gp.close f
-
-
+  
+  
 (* plot all of the above in a multiplot setting *)
 let _ =
   let f = Gp.figure() in
   Gp.send ["set multiplot layout 2,2"] f;
   Gp.plot [[unif],"w p pt 7 lc 7 ps 0.2"] f;
   Gp.plot [[unif],"w p pt 7 lc 7 ps 0.1";
-	   [expo],"w p pt 7 lc 1 ps 0.1"] f;
+    [expo],"w p pt 7 lc 1 ps 0.1"] f;
   Gp.plot [[x;y1],"w l ls 1";
-	   [x;y2],"w l ls 3"] f;
+    [x;y2],"w l ls 3"] f;
   Gp.plot [[unif],"u 1:0:(0.01) w l ls 7 smooth kdensity"] f;
   Gp.send ["unset multiplot"] f;
   Gp.close f
-
-
-
+  
+  
+  
 (* there is a shortcut for that, which takes care of the alignment *)
-let _ = 
+let _ =
   let f = Gp.figure() in
-  Gp.multiplot 2 2 0.1 0.1 
-    [ Gp.plot [[unif],"w p pt 7 lc 7 ps 0.2"];
-      Gp.plot [[unif],"w p pt 7 lc 7 ps 0.1";
-	       [expo],"w p pt 7 lc 1 ps 0.1"];
-      Gp.plot [[x;y1],"w l ls 1";
-	       [x;y2],"w l ls 3"];
-      Gp.plot [[unif],"u 1:0:(0.01) w l ls 7 smooth kdensity"] ]
-    f;
+  Gp.multiplot 2 2 0.1 0.1
+  [ Gp.plot [[unif],"w p pt 7 lc 7 ps 0.2"];
+    Gp.plot [[unif],"w p pt 7 lc 7 ps 0.1";
+      [expo],"w p pt 7 lc 1 ps 0.1"];
+    Gp.plot [[x;y1],"w l ls 1";
+      [x;y2],"w l ls 3"];
+    Gp.plot [[unif],"u 1:0:(0.01) w l ls 7 smooth kdensity"] ]
+  f;
   Gp.close f
 open Printf
 
 let gnuplot = "gnuplot" (* command name *)
-    
+  
 type t = out_channel
-    
+  
 let figure ?device () =
-    let f = Unix.open_process_out gnuplot in
-    begin match device with
-        | None -> output_string f "set term wxt enhanced persist\n"
-        | Some (terminal,"") -> output_string f (sprintf "set term %s\n" terminal);
-        | Some (terminal,file) -> (
-            output_string f (sprintf "set term %s\n" terminal) ;
-            output_string f (sprintf "set output '%s'\n" file))
-    end;
-    f
-    
+  let f = Unix.open_process_out gnuplot in
+  begin match device with
+    | None -> output_string f "set term wxt enhanced persist\n"
+    | Some (terminal,"") -> output_string f (sprintf "set term %s\n" terminal);
+    | Some (terminal,file) -> (
+          output_string f (sprintf "set term %s\n" terminal) ;
+          output_string f (sprintf "set output '%s'\n" file))
+  end;
+  f
+  
 let send list (f:t) = List.iter (fun s -> output_string f (s^"\n")) list
-    
+  
 let flush = flush
-    
+  
 let close f = ignore (Unix.close_process_out f)
-    
+  
 let end_signal f = fprintf f "e\n%!"
-    
+  
 let send_columns m f =
-    let cols = Array.length m in
-    let rows = Array.fold_left max (-1) (Array.map Array.length m) in
-    for i=0 to rows-1 do
-        for j=0 to cols-1 do
-            let mj = m.(j) in
-            if i<Array.length mj
-            then fprintf f "%f " mj.(i)
-            else fprintf f "- ";
-        done; fprintf f "\n%!";
-    done;
-    end_signal f
-    
-    
-    (* for some reason, gnuplot wants a double "e" at the end
+  let cols = Array.length m in
+  let rows = Array.fold_left max (-1) (Array.map Array.length m) in
+  for i=0 to rows-1 do
+    for j=0 to cols-1 do
+      let mj = m.(j) in
+      if i<Array.length mj
+      then fprintf f "%f " mj.(i)
+      else fprintf f "- ";
+    done; fprintf f "\n%!";
+  done;
+  end_signal f
+  
+  
+  (* for some reason, gnuplot wants a double "e" at the end
      of the stream for matrix data given to [splot()] ... *)
-    
+  
 let send_matrix m f =
-    send_columns m f;
-    fprintf f "e\n%!"
-    
+  send_columns m f;
+  end_signal f
+  
 let plot data f =
-    let cmds = List.map (fun (_,opts) -> sprintf "'-' %s" opts) data in
-    let cmd = "plot " ^ String.concat ", " cmds in
-    send [cmd] f;
-    List.iter (fun (d,_) -> send_columns (Array.of_list d) f) data
-    
-    
+  let cmds = List.map (fun (_,opts) -> sprintf "'-' %s" opts) data in
+  let cmd = "plot " ^ String.concat ", " cmds in
+  send [cmd] f;
+  List.iter (fun (d,_) -> send_columns (Array.of_list d) f) data
+  
+  
 let splot data f =
-    let mat,opts = data in
-    send ["set pm3d map"; "set key noautotitle"] f;
-    let n = Array.length mat and m = Array.length mat.(0) in
-    send [
-        sprintf "set xrange [%f:%f]" (-0.5) (float n -. 0.5);
-        sprintf "set yrange [%f:%f] reverse" (-0.5) (float m -. 0.5);
-        sprintf "splot '-' %s" opts
-    ] f;
-    send_matrix mat f
-    
+  let mat,opts = data in
+  send ["set pm3d map"; "set key noautotitle"] f;
+  let n = Array.length mat and m = Array.length mat.(0) in
+  send [
+    sprintf "set xrange [%f:%f]" (-0.5) (float n -. 0.5);
+    sprintf "set yrange [%f:%f] reverse" (-0.5) (float m -. 0.5);
+    sprintf "splot '-' %s" opts
+  ] f;
+  send_matrix mat f
+  
 let margins ?t ?b ?l ?r f =
-    let setm s x = match x with
-        | Some m -> send [sprintf "set %smargin at screen %f" s m] f
-        | None -> () in
-    setm "t" t; setm "b" b; setm "l" l; setm "r" r
-    
+  let setm s x = match x with
+    | Some m -> send [sprintf "set %smargin at screen %f" s m] f
+    | None -> () in
+  setm "t" t; setm "b" b; setm "l" l; setm "r" r
+  
 let xrange a b f =
-    send [sprintf "set xrange [%f:%f]" a b] f
-    
+  send [sprintf "set xrange [%f:%f]" a b] f
+  
 let yrange a b f =
-    send [sprintf "set yrange [%f:%f]" a b] f
-    
+  send [sprintf "set yrange [%f:%f]" a b] f
+  
 let title s f =
-    send [sprintf "set title '%s'" s] f
-    
+  send [sprintf "set title '%s'" s] f
+  
 let multiplot rows cols vspace hspace list f =
-    send [sprintf "set multiplot layout %i,%i" rows cols] f;
-    let plots = Array.of_list list in
-    let hrem = 2. *. hspace *. float cols
-    and vrem = 2. *. vspace *. float rows in
-    let width = (1. -. hrem) /. float cols
-    and height = (1. -. vrem) /. float rows in
-    for k=0 to Array.length plots - 1 do
-        let row = k/cols and col = k mod cols in
-        let t = 1. -. hspace -. 2. *. hspace *. float row -. height *. float row in
-        let b = t -. height in
-        let l = 1. -. (1. -. vspace -. 2. *. vspace *. float col -. width *. float col) in
-        let r = l +. width in
-        margins ~t ~b ~l ~r f;
-        plots.(k) f;
-    done;
-    send ["unset multiplot"] f
-    
-    
+  send [sprintf "set multiplot layout %i,%i" rows cols] f;
+  let plots = Array.of_list list in
+  let hrem = 2. *. hspace *. float cols
+  and vrem = 2. *. vspace *. float rows in
+  let width = (1. -. hrem) /. float cols
+  and height = (1. -. vrem) /. float rows in
+  for k=0 to Array.length plots - 1 do
+    let row = k/cols and col = k mod cols in
+    let t = 1. -. hspace -. 2. *. hspace *. float row -. height *. float row in
+    let b = t -. height in
+    let l = 1. -. (1. -. vspace -. 2. *. vspace *. float col -. width *. float col) in
+    let r = l +. width in
+    margins ~t ~b ~l ~r f;
+    plots.(k) f;
+  done;
+  send ["unset multiplot"] f
+  
+  
 let quick doThis =
-    let f = figure() in
-    doThis f;
-    close f
-    
-
+  let f = figure() in
+  doThis f;
+  close f
+  
+  
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.