Source

opycaml / examples / matplotlib / hist2d_demo.ml

module Api = Opycaml.Api
open Api
open Opycaml.Xapi

let debug = Object.debug

let main () =
  (* from pylab import * *)
  let pylab = import_module "pylab" in

  let randn x = call_obj (pylab % "randn") [x] |> Number.coerce in

  let x = Number.add (randn (Py.of_int 1000)) (Py.of_int 5) in
  let y = randn (Py.of_int 1000) in
  
  call_obj_ (pylab % "hist2d") [x; y] ~kwd:[ "bins", Py.of_int 40 ];
  call_obj_ (pylab % "show") []


let () = 
  try main () with
  | Api.Error(ty, detail) -> 
      prerr_endline "Expected type error!";
      debug ty "type";
      debug detail "detail";