# OCaml plotting libraries

**URL:** <https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384>\
**Category:** Ecosystem\
**Created:** [November 8, 2023, 10:20am UTC](https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384 "2023-11-08T10:20:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [November 8, 2023, 10:20am UTC](https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384/1 "2023-11-08T10:20:59Z")

</div>

Continuing the discussion from [[ANN] First release of OCaml bindings to the Polars dataframe library](https://discuss.ocaml.org/t/ann-first-release-of-ocaml-bindings-to-the-polars-dataframe-library/13382/3):

> [@\[ANN\] First release of OCaml bindings to the Polars dataframe library](https://discuss.ocaml.org/t/ann-first-release-of-ocaml-bindings-to-the-polars-dataframe-library/13382/3):
>
> > Also, what would you recommend for interactive plotting?
> 
> I haven’t personally tried it yet, but I think @laurent 's [GitHub - LaurentMazare/ocaml-matplotlib: Plotting for ocaml based on matplotlib.pyplot](https://github.com/LaurentMazare/ocaml-matplotlib) library should work with ocaml-jupyter so would probably be worth trying out.

There’s also [sanette/oplot: Mathematical plotting library for ocaml](https://github.com/sanette/oplot).

If you’re interested, I might polish and release (or upstream to PrintBox) [a tiny utility](https://github.com/lukstafi/ocannl/blob/master/lib/PrintBox_utils.ml) for plotting in text (useful for expect tests or CLI interfaces).

---

<div class="post-metadata">

**Author:** ![UnixJunkie](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/unixjunkie/32/638_2.png) [@UnixJunkie](https://discuss.ocaml.org/u/UnixJunkie)\
**Post date:** [November 9, 2023, 12:26am UTC](https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384/2 "2023-11-09T00:26:27Z")

</div>

```bash
opam search plot

```

returns a long list; some are libraries to help with ploting.

---

<div class="post-metadata">

**Author:** ![mt-caret](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/mt-caret/32/4506_2.png) [@mt-caret](https://discuss.ocaml.org/u/mt-caret)\
**Post date:** [November 9, 2023, 1:16pm UTC](https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384/3 "2023-11-09T13:16:05Z")

</div>

> [@lukstafi](#):
>
> If you’re interested, I might polish and release (or upstream to PrintBox) [a tiny utility](https://github.com/lukstafi/ocannl/blob/master/lib/PrintBox_utils.ml) for plotting in text (useful for expect tests or CLI interfaces).

Wow, this looks quite useful! I think I’d definitely use it my libraries it if it were available on opam!

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [November 9, 2023, 1:38pm UTC](https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384/4 "2023-11-09T13:38:45Z")

</div>

- [Archimedes](https://github.com/Chris00/ocaml-archimedes) – native OCaml
- [oplot](https://github.com/sanette/oplot) – native OCaml, also [with a gui](https://github.com/sanette/goplot)
- [`gnuplot`](http://www.gnuplot.info/) – C: bindings [gnuplot](https://github.com/c-cube/ocaml-gnuplot/) and [`prbnmcn-gnuplot`](https://github.com/igarnier/prbnmcn-gnuplot) (simple interface subset)
- [`matplotlib`](http://matplotlib.sourceforge.net/) – Python: bindings [`matplotlib`](https://github.com/LaurentMazare/ocaml-matplotlib)
  - apparently it [cannot directly plot function expressions](https://stackoverflow.com/a/60384302/484129)?

- [`plplot`](https://plplot.sourceforge.net/) – C: bindings [`plplot`](https://github.com/hcarty/ocaml-plplot/) (`owl-plplot` got removed)
- [`plotly`](https://plotly.com/python/) – Python: bindings [`plotly`](https://github.com/camlspotter/plotly-ocaml)

---

<div class="post-metadata">

**Author:** ![RChG](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/rchg/32/4158_2.png) [@RChG](https://discuss.ocaml.org/u/RChG)\
**Post date:** [November 9, 2023, 3:31pm UTC](https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384/5 "2023-11-09T15:31:08Z")

</div>

Other library:

[ocaml-gr](https://github.com/mseri/ocaml-gr) → It is a binding of a C-library which aims to be fast, and it is used in the Julia comunity as a backend of several more highlevel libraries.

[ocaml-vega-lite](https://github.com/apatil/ocaml-vega-lite) → I guess it produces json documents to be plotted with vega-lite

I’m not an expert but in OCaml there are a bindings to Cairo library, which is widely used to build plotting libraries on top of it. Maybe something like [ocaml-gg](https://erratique.ch/software/gg) would be an alternative.

---

<div class="post-metadata">

**Author:** ![paurkedal](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/paurkedal/32/586_2.png) [@paurkedal](https://discuss.ocaml.org/u/paurkedal)\
**Post date:** [November 9, 2023, 6:34pm UTC](https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384/6 "2023-11-09T18:34:13Z")

</div>

For those who want to try something new, I’ve found the following procedure to work:

```sh
opan pin gg --dev-repo
opam pin vg --dev-repo
opam pin https://github.com/dbuenzli/vz.git

```

then patch up

```diff
--- .opam/5.1.0/lib/vz/META.orig	2023-11-09 19:17:31.897443541 +0100
+++ .opam/5.1.0/lib/vz/META	2023-11-09 19:19:34.731868303 +0100
@@ -34,7 +34,7 @@
   description = "Quick cartesian plots of datasets"
   version = "0.0.0-35-g2667067"
   directory = "plot"
- requires = "gg vg vz evidence"
+ requires = "gg vg vz vz.evidence"
   archive(byte) = "vz_plot.cma"
   archive(native) = "vz_plot.cmxa"
   plugin(byte) = "vz_plot.cma"
@@ -57,7 +57,7 @@
   description = "Evidence sample data"
   version = "0.0.0-35-g2667067"
   directory = "samples"
- requires = "evidence"
+ requires = "vz.evidence"
   archive(byte) = "evidence_samples.cma"
   archive(native) = "evidence_samples.cmxa"
   plugin(byte) = "evidence_samples.cma"

```

and hunt for examples and docs at [Vz / Erratique](https://erratique.ch/software/vz). I’m looking forward to stable release.

---

<div class="post-metadata">

**Author:** ![lukstafi](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lukstafi/32/3442_2.png) [@lukstafi](https://discuss.ocaml.org/u/lukstafi)\
**Post date:** [October 9, 2024, 10:21am UTC](https://discuss.ocaml.org/t/ocaml-plotting-libraries/13384/7 "2024-10-09T10:21:52Z")

</div>

This is available now as a PrintBox extension package [printbox-ext-plot](https://ocaml.org/p/printbox-ext-plot/latest):  
[printbox/src/printbox-ext-plot page with examples](https://github.com/c-cube/printbox/tree/main/src/printbox-ext-plot).
