# gp / examples / ex.ml

 ``` 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``` ```let _ = Random.self_init () (* generate some random data *) let unif = Array.init 1000 (fun _ -> Random.float 1.) (* simple y-vector plot *) 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; 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" ]) (* 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 f = Gp.figure() in Gp.plot [[x;y1],"w l ls 1"; [x;y2],"w l ls 3"] 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 (* 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; Gp.plot [[x;y1],"w l ls 1"; [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 (* there is a shortcut for that, which takes care of the alignment *) 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 *) ```
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.