Trouble with owl-plplot

I was trying to follow the Owl “Create Plots” example, making adjustments for what seem to be changes in the module names and API after this tutorial was written.

When I run the program, I get a seemingly endless stream of error messages.

Is there something wrong with my code, something wrong with my installation, or something wrong with the library? And why is it printing error messages instead of raising an exception?

Here’s what I have:

$ cat simple_plot.ml
(* open Owl_plplot.Plot *)

module P =  Owl_plplot.Plot

let main () =
  let f x = Owl_maths.sin x /. x in
  let plotfile = "./plot.png" in 
  let h = (P.create ~m:900 ~n:675 plotfile) in


  P.set_title h "Function f(x) = sin(x) / x";
  P.set_xlabel h "x";
  P.set_ylabel h "y";
  P.set_font_size h 8.;
  P.set_pen_size h 3.;
  P.plot_fun ~h f 1. 15.;
  P.output h;
  Printf.printf "Wrote image file %s\n" plotfile

let _ = main ()

$ ocamlfind ocamlopt -linkpkg -package owl -package owl-plplot -o simple_plot simple_plot.ml
$ ./simple_plot
qt5ct: using qt5ct plugin

*** PLPLOT ERROR, ABORTING OPERATION ***
plvpor: Invalid limits, aborting operation

*** PLPLOT ERROR, ABORTING OPERATION ***
plwind: Please set up viewport first, aborting operation

*** PLPLOT ERROR, ABORTING OPERATION ***
plbox: Please set up window first, aborting operation

*** PLPLOT ERROR, ABORTING OPERATION ***
pllab: Please set up viewport first, aborting operation

*** PLPLOT ERROR, ABORTING OPERATION ***
plline: Please set up window first, aborting operation

*** PLPLOT ERROR, ABORTING OPERATION ***
plvpor: Invalid limits, aborting operation

It kept cycling through those error messages until I interrupted it.

Oh! By omitting ~m:900 ~n:675 I can avoid the errors! But why?

Maybe what I need to know is how to properly use optional arguments?

1 Like

The m and n parameters are for subplots, not dimensions of your plot window. Thus, you need to create m*n subplots before rendering.

See the subplots portion of the documentation. It would be nice if an exception was raised with an informative message for the user, however.

1 Like

Oh, that explains a lot, doesn’t it?

And it even says that’s what they’re for in the example, but I must have dozed off when reading that part. :blush:

Thanks a lot!

1 Like