What do you use to plot a list of (x,y) coordinates

I guess I should use Owl, but all I find in the plot documentation of Owl are functions that take functions and not a list of points as argument. A function that takes a x and a y list as the pythonic matplotlib.pyplot.plot would work too.

1 Like

Under Plot Figures — Owl Numerical Library 0.3 documentation, there’s an example of a use of Plot that takes a matrix of x and y points as input:

let x = Mat.linspace 0. 2. 100 in
let y0 = Mat.sigmoid x in
let y1 = Mat.map Maths.sin x in
let h = Plot.create "" in
Plot.(plot ~h ~spec:[ RGB (255,0,0); LineStyle 1; Marker "#[0x2299]"; MarkerSize 8. ] x y0);
Plot.(plot ~h ~spec:[ RGB (0,255,0); LineStyle 2; Marker "#[0x0394]"; MarkerSize 8. ] x y1);
Plot.(legend_on h ~position:SouthEast [|"sigmoid"; "sine"|]);
Plot.output h;;

So I guess you can use that if you convert your list of points to a matrix.


There is also archimedes.

1 Like

@fccm where can I find the documentation ?


1 Like

I also found this example | notebook.community

1 Like

If you want something catchy to embed into an html page you can also use open-flash-chart.

There was an old binding for the Flash version of this lib in the past which is dead now because of Flash, but the json exchange format is maybe still the same.

You can also use oplot Oplot (oplot.Oplot)
For instance, in a toplevel

#require "oplot";;
open Oplot;;
let a = Plt.axis 0. 0.;;
let view = Plt.view 0. 0. 2. 1.;;
let sh = Plt.dot_plot ~view ~dot:Plt.diamond [(0.,1.); (1.,0.1); (0.5, 0.3); (2.,0.5)];;
Plt.display (List.append sh [Plt.(Color black); a]);;

This will plot your points as “diamonds”.
(the axis and the view are not obligatory)


gnuplot, what else? :wink:

People with less taste might use a wrapper for it; such as:


I just see that there are also ocaml bindings for Charts.js in Opam.

We also have (unreleased) vega-lite bindings here:

It’s a pretty high-level way of plotting in the browser, by generating
a json description of the plot. More here: A High-Level Grammar of Interactive Graphics | Vega-Lite


I also found some older vega-lite bindings generated directly from the JSON schema here: GitHub - apatil/ocaml-vega-lite: Complete, typesafe representation of Vega-Lite in OCaml, unfortunately for an old version of Vega Lite.
I’ve attempted to update that to Vega Lite v5: GitHub - edwintorok/ocaml-vega-lite at v5

The advantage of generating from the json schema is that you get some (minimal) docs for the various functions/types/fields, and that it covers the entire API. However the generated code has quite tedious use of variants (json could dynamically determine the type, but in OCaml we have to be explicit). In some cases the merging of variants the generator does helps a bit (so you don’t have multiple levels of polymorphic variants), but this tends to break, my update above is just very minimal to get it to compile, the interface isn’t very ergonomic (yet).

A manually written binding would have the advantage of a nicer API (but with limited coverage given how big Vega Lite’s API has grown), both approaches have their own strengths.

If all you need to do is plot (x,y) values then you could attempt to build the vega lite representation using any of the available tools/editors/examples (Vega-Lite Ecosystem | Vega-Lite) and then plug in your data source using one of the supported formats, e.g. csv which should be fairly easy to generate from OCaml: Data | Vega-Lite

1 Like