1
+ open Owl
2
+ open Owl_plplot
3
+
4
+ let _ =
5
+ let h = Plot. create " plot_024.png" in
6
+ Plot. (plot_fun ~h ~spec: [ RGB (0 ,0 ,255 ); Marker " #[0x2299]" ; MarkerSize 8. ] Maths. sin 0. 9. );
7
+ Plot. (plot_fun ~h ~spec: [ RGB (255 ,0 ,0 ); Marker " #[0x0394]" ; MarkerSize 8. ] Maths. cos 0. 9. );
8
+ Plot. legend_on h [|" Sine function" ; " Cosine function" |];
9
+ Plot. output h
10
+
11
+
12
+ let _ =
13
+ let g x = (Stats. gaussian_pdf x ~mu: 0. ~sigma: 1. ) *. 100. in
14
+ let y = Mat. gaussian ~mu: 0. ~sigma: 1. 1 1000 in
15
+
16
+ (* plot multiple data sets *)
17
+ let h = Plot. create " plot_025.png" in
18
+ Plot. set_background_color h 255 255 255 ;
19
+ Plot. (histogram ~h ~spec: [ RGB (255 ,0 ,50 ) ] ~bin: 100 y);
20
+ Plot. (plot_fun ~h ~spec: [ RGB (0 ,0 ,255 ); LineWidth 2. ] g (- 4. ) 4. );
21
+ Plot. legend_on h [|" data" ; " model" |];
22
+
23
+ Plot. output h
24
+
25
+
26
+ let _ =
27
+ let x = Mat. (uniform 1 20 *$ 10. ) in
28
+ let y = Mat. (uniform 1 20 ) in
29
+ let z = Mat. gaussian 1 20 in
30
+
31
+ (* plot multiple data sets *)
32
+ let h = Plot. create " plot_026.png" in
33
+ Plot. (plot_fun ~h ~spec: [ RGB (0 ,0 ,255 ); LineStyle 1 ; Marker " *" ] Maths. sin 1. 8. );
34
+ Plot. (plot_fun ~h ~spec: [ RGB (0 ,255 ,0 ); LineStyle 2 ; Marker " +" ] Maths. cos 1. 8. );
35
+ Plot. scatter ~h x y;
36
+ Plot. stem ~h x z;
37
+
38
+ let u = Mat. (abs(gaussian 1 10 *$ 0.3 )) in
39
+ Plot. (bar ~h ~spec: [ RGB (255 ,255 ,0 ); FillPattern 3 ] u);
40
+
41
+ let v = Mat. (neg u *$ 0.3 ) in
42
+ let u = Mat. sequential 1 10 in
43
+ Plot. (area ~h ~spec: [ RGB (0 ,255 ,0 ); FillPattern 4 ] u v);
44
+
45
+ (* set up legend *)
46
+ Plot. (legend_on h ~position: NorthEast [|" test 1" ; " test 2" ; " scatter" ; " stem" ; " bar" ; " area" |]);
47
+ Plot. output h
48
+
49
+
50
+ let _ =
51
+ let h = Plot. create " plot_004.png" in
52
+ Plot. set_background_color h 255 255 255 ;
53
+ Plot. set_pen_size h 2. ;
54
+ Plot. (draw_line ~h ~spec: [ LineStyle 1 ] 1. 1. 9. 1. );
55
+ Plot. (draw_line ~h ~spec: [ LineStyle 2 ] 1. 2. 9. 2. );
56
+ Plot. (draw_line ~h ~spec: [ LineStyle 3 ] 1. 3. 9. 3. );
57
+ Plot. (draw_line ~h ~spec: [ LineStyle 4 ] 1. 4. 9. 4. );
58
+ Plot. (draw_line ~h ~spec: [ LineStyle 5 ] 1. 5. 9. 5. );
59
+ Plot. (draw_line ~h ~spec: [ LineStyle 6 ] 1. 6. 9. 6. );
60
+ Plot. (draw_line ~h ~spec: [ LineStyle 7 ] 1. 7. 9. 7. );
61
+ Plot. (draw_line ~h ~spec: [ LineStyle 8 ] 1. 8. 9. 8. );
62
+ Plot. set_xrange h 0. 10. ;
63
+ Plot. set_yrange h 0. 9. ;
64
+ Plot. output h
65
+
66
+
67
+ let _ =
68
+ let h = Plot. create " plot_005.png" in
69
+
70
+ Array. init 9 (fun i ->
71
+ let x0, y0 = 0.5 , float_of_int i +. 1.0 in
72
+ let x1, y1 = 4.5 , float_of_int i +. 0.5 in
73
+ Plot. (draw_rect ~h ~spec: [ FillPattern i ] x0 y0 x1 y1);
74
+ Plot. (text ~h ~spec: [ RGB (0 ,255 ,0 ) ] 2.3 (y0-. 0.2 ) (" pattern: " ^ (string_of_int i)))
75
+ ) |> ignore;
76
+
77
+ Plot. output h
78
+
79
+
80
+ let _ =
81
+ let x = Mat. linspace 0. 2. 100 in
82
+ let y0 = Mat. sigmoid x in
83
+ let y1 = Mat. map Maths. sin x in
84
+ let h = Plot. create " plot_022.png" in
85
+ Plot. (plot ~h ~spec: [ RGB (255 ,0 ,0 ); LineStyle 1 ; Marker " #[0x2299]" ; MarkerSize 8. ] x y0);
86
+ Plot. (plot ~h ~spec: [ RGB (0 ,255 ,0 ); LineStyle 2 ; Marker " #[0x0394]" ; MarkerSize 8. ] x y1);
87
+ Plot. (legend_on h ~position: SouthEast [|" sigmoid" ; " sine" |]);
88
+ Plot. output h
89
+
90
+
91
+ let _ =
92
+ let x = Mat. linspace 0. 6.5 20 in
93
+ let y = Mat. map Maths. sin x in
94
+ let h = Plot. create ~m: 1 ~n: 2 " plot_007.png" in
95
+ Plot. set_background_color h 255 255 255 ;
96
+ Plot. subplot h 0 0 ;
97
+ Plot. plot_fun ~h Maths. sin 0. 6.5 ;
98
+ Plot. (stairs ~h ~spec: [ RGB (0 ,128 ,255 ) ] x y);
99
+ Plot. subplot h 0 1 ;
100
+ Plot. (plot ~h ~spec: [ RGB (0 ,0 ,0 ) ] x y);
101
+ Plot. (stairs ~h ~spec: [ RGB (0 ,128 ,255 ) ] x y);
102
+ Plot. output h
103
+
104
+
105
+ let _ =
106
+ let x = Mat. linspace 0. 8. 100 in
107
+ let y = Mat. map Maths. atan x in
108
+ let h = Plot. create ~m: 1 ~n: 2 " plot_011.png" in
109
+ Plot. subplot h 0 0 ;
110
+ Plot. (area ~h ~spec: [ FillPattern 1 ] x y);
111
+ let x = Mat. linspace 0. (2. *. 3.1416 ) 100 in
112
+ let y = Mat. map Maths. sin x in
113
+ Plot. subplot h 0 1 ;
114
+ Plot. (area ~h ~spec: [ FillPattern 2 ] x y);
115
+ Plot. output h
0 commit comments