1(*
2  Bar chart demo.
3*)
4
5open Plplot
6
7let plfbox x0 y0 =
8  let x = [|x0; x0; x0 +. 1.0; x0 +. 1.0|] in
9  let y = [|0.0; y0; y0; 0.0|] in
10  plfill x y;
11  plcol0 1;
12  pllsty 1;
13  plline x y;
14  ()
15
16(*--------------------------------------------------------------------------*\
17 * Does a simple bar chart, using color fill.  If color fill is
18 * unavailable, pattern fill is used instead (automatic).
19\*--------------------------------------------------------------------------*)
20
21let pos = [|0.0; 0.25; 0.5; 0.75; 1.0|]
22let red = [|0.0; 0.25; 0.5; 1.00; 1.0|]
23let green = [|1.0; 0.50; 0.5; 0.50; 1.0|]
24let blue = [|1.0; 1.0; 0.5; 0.25; 0.0|]
25
26let () =
27  (* Parse and process command line arguments *)
28  plparseopts Sys.argv [PL_PARSE_FULL];
29
30  (* Initialize plplot *)
31  plinit ();
32
33  pladv 0;
34  plvsta ();
35  plwind 1980.0 1990.0 0.0 35.0;
36  plbox "bc" 1.0 0 "bcnv" 10.0 0;
37  plcol0 2;
38  pllab "Year" "Widget Sales (millions)" "#frPLplot Example 12";
39
40  let y0 = [|5.0; 15.0; 12.0; 24.0; 28.0; 30.0; 20.0; 8.0; 12.0; 3.0|] in
41
42  plscmap1l true pos red green blue None;
43
44  for i = 0 to 9 do
45    (* plcol0 (i + 1); *)
46    plcol1(float_of_int i /. 9.0);
47    plpsty 0;
48    plfbox (1980.0 +. float_of_int i) y0.(i);
49    let text = Printf.sprintf "%.0f" y0.(i) in
50    plptex (1980.0 +. float_of_int i +. 0.5) (y0.(i) +. 1.0) 1.0 0.0 0.5 text;
51    let text = string_of_int (1980 + i) in
52    plmtex "b" 1.0 (float_of_int (i + 1) *. 0.1 -. 0.05) 0.5 text;
53  done;
54
55  (* Don't forget to call plend() to finish off! *)
56  plend ();
57  ()
58
59